Removing the form

  • Thread starter Thread starter Stephan Ainley
  • Start date Start date
S

Stephan Ainley

Hello, I'm wondering what would be the best way to remove the main form from
a project, or at least hide it. My program is going to use a NotifyIcon
control to be in the system tray. I'd like to be able to open other forms
but don't need a main one. Is the only thing to set the opacity to 0%?

thanks
 
Hi,

The "main" form is just like another form except that it's the one that is
created in the main() method, just set the correct properties of it and you
will never see it. IIRC you have to:
1- Set the status to minimized
2- Remove it from the taskbar
3- Remove it from the app listing ( control+tab )

and of course create the NotifyIcon :)

Just let me know if you want any code, I have an application like it.

Cheers,
 
Stephan Ainley said:
Hello, I'm wondering what would be the best way to remove the main form from
a project, or at least hide it. My program is going to use a NotifyIcon
control to be in the system tray. I'd like to be able to open other forms
but don't need a main one. Is the only thing to set the opacity to 0%?

thanks
I suggest you look up "Form class" in the Visual Studio help. Form objects
have a Visible property, which may be what you are wanting, or you might
want to use the Hide() method. There are also Close() and Show() methods
which might be useful to you.
 
ShowInTaskbar = false
WindowState = Minimized

private void frmMain_Load(object sender, System.EventArgs e)

{

notifyIcon1.Icon = this.Icon;

}



private void frmMain_Resize(object sender, System.EventArgs e)

{

if (WindowState == FormWindowState.Minimized) Hide();

}

private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)

{

Show();

WindowState = FormWindowState.Normal;

}
 
Hi Claire,

IIRC this will still show the app when using control+tab , to avoid that I
know that I had to use P/Invoke (don't remember the exact method)
Maybe setting the Form.Text = "" solved this?

Cheers,
 
Yes this worked, thank you all very much. At first it didn't work because I
had the form border style as a fixed dialog (to get rid of the app in the
alt+tab) but I changed it to a fixed single and that worked.

Also if anyone else is interested I added this on form closing:

e.Cancel = true;
this.WindowState = FormWindowState.Minimized;

so that the app could not be exited through the form. Since I wanted the
form to act as a property form then exit the app this is perfect.
 
Back
Top