Reputation: 1313
Whenever i use this.Hide(); the form closes and does not just hide?? I am planning to use this.Hide(); to minimize my form to the system tray.
This closes the form..
private void label14_Click(object sender, EventArgs e)
{
this.Hide();
}
This form is the second form that starts up, and it is called from the first form like this:
Form frm = new Main();
frm.ShowDialog();
I did try to use frm.Show(); but then the program terminates again.. So the problem lies in the way the form is first started i would guess?
EDIT: I had to change the way the form was called. I had to use this.hide instead of this.close on the first form.
Upvotes: 1
Views: 1848
Reputation: 4244
Hide method set visibility only. Close also dispose internal objects!
Upvotes: 0
Reputation: 5755
You have to do this instead:
this.WindowState = FormWindowState.Minimized;
Actually when use Hide(), the form is still open but hidden somewhere. So in my opinion using Hide() method and creating a new object again to show the form is not the right move. To switch between them, it is better to make a form manager class.
According to the comment, this may solve the problem (if simply calling the Show() method cannot be applied) :
Form1 form = Application.OpenForms["Form1"] as Form1 ;
if (form != null)
{
form.Show();
}
Upvotes: 2