3

Currently I am developing a windows form application in c# that has several forms.

I am running a background form that operates the notifyicon property that allows the icon to appear in the taskbar.

When I launch the program, it will launch a loginForm, after which logging in it will go into a mainForm. After closing the mainForm, the application does not close yet, which in this case works like Windows Live Messenger.

How do I make my program in a way that after I the mainForm, through double clicking it will bring the form back up? (Like how MSN works.)

Or is it a better solution for me to close the whole application when I press the X button in the title bar. Which brings up another problem for me as I cant seem to exit the application when I close other forms other than the main form.

svick
  • 236,525
  • 50
  • 385
  • 514
Thomas
  • 1,126
  • 6
  • 21
  • 39
  • You cannot open a closed form, that fails with ObjectDisposedException. Create a new one. I have to guess that your (hidden) login form keeps the app running. It isn't clear. – Hans Passant Oct 31 '11 at 13:20

2 Answers2

3

Probably you have NotifyIcon on your main form. Subscribe on the DoubleClick event of this control and change state of your main form in the handler:

    private void notifyIcon1_DoubleClick(object sender, EventArgs e)
    {
        this.Show();
        this.Visible = true;
        this.WindowState = FormWindowState.Normal;
    }
Samich
  • 29,157
  • 6
  • 68
  • 77
0

Just set the Visible property of the form to true/false. Or you could call Show()/Hide().

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445