Perhaps this has something to do with it being the mainForm, but I'll ask the question. I have my mainForm that is the first to load when the program is booted.
I then click a button called Add, which should open a new form, and close the mainForm.
The problem is, is shows the new form for a split second, then closes both.
The code:
private void addFrmBtn_Click(object sender, EventArgs e)
{
saveForm saveform = new saveForm();
saveform.Show();
this.Close();
}
In your Program.Main()
method, you probably have something like this:
class Program
{
void Main()
{
Application.Run(new MainForm());
}
}
This means your application's message loop is running around the main form. Once that closes, the application's main UI thread goes with it.
You can either:
Program.Main()
method so that this doesn't happen (there are overloads to Application.Run()
.MainForm
rather than closing it.Here's how you do option 3:
private void addFrmBtn_Click(object sender, EventArgs e)
{
saveForm saveform = new saveForm();
saveform.Show();
this.Hide();
}
The problem seems, is you are closing the parent form which opened the child form. To retain the form use this.Hide(); instead of close.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With