Reputation: 7092
I have a MainForm
, from the MainForm
i call the ConfirmationForm
,
using (var f = new ConfirmationForm())
f.ShowDialog();
Then in the ConfirmationForm
, i want to show the another UsersListForm
if (ConfirmSuccess)
{
this.Hide; //or this.Close
using (var f = new UsersListForm())
f.ShowDialog();
}
Now, when the ConfirmSuccess is equal to true the MainForm
will Hide
or Close
too.
How to prevent that the MainForm
will not to Hide
or Close
? any idea? Thanks in advance.
UPDATE: My problem is solve. I call first the UsersListForm
and from the load event of UsersListForm
I call the ConfirmationForm then I use DialogResult == System.Windows.Forms.DialogResult.OK
and everythings is fine now :)
Upvotes: 0
Views: 1192
Reputation: 662
If your intention is to request user confirmation before opening the MainForm, the best way to do this would include you call and confirmation form after creating it and call MainForm. If your intention is to seek confirmation at the beginning of the application, place the call ConfirmationForm within the Program class before the Application.Run (new MainForm ());
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
ConfirmationForm confForm = new ConfirmationForm();
confForm.ShowDialog();
Application.Run(new MainForm());
}
}
But if the intention is to request verification within the application in a separate call point, you should call the ConfirmationForm with ShowDialog and after that call the desired form.
But if your intention really is to verify the request with the open form, and hiding it, you can use the DialogResult property of ConfirmationForm to return the success or failure of the validation by comparing (ConfirmationForm.ShowDialog () == DialogResult.OK
). See this example
Upvotes: 1