How To Have a Form Not Open Upon Executing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an application that I am writing that is to run on the users system
tray. I can get the icon and application to run on the system tray, no
problem. However: when I run the app: a form window also opens, although
nothing is displayed on this form. How do I get it to run without the main
form window from opening as well?

Thanks
Andy
 
Following is cut from my application.

My form is hiding in taskbar on startup.
The following also cures a bug in current .net/visual studio where Windows
won't shut down if the application is minimized. (the WndProc bit)

Form properties:
ShowInTaskbar to false
WindowState = minimized

private void frmOptions_Load(object sender, System.EventArgs e)
{
notifyIcon1.Icon = this.Icon;
}

#region WINDOWMINIMIZE
private void frmOptions_Resize(object sender, System.EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
ShowInTaskbar = false;
Hide();
}
}
private void mnuOptions_Click(object sender, System.EventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
ShowInTaskbar = true;
BringToFront();
}
private bool DOCLOSE = false;
private void mnuClose_Click(object sender, System.EventArgs e)
{
DOCLOSE = true;
Close();
}
private void frmOptions_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
if (DOCLOSE == false)
{
e.Cancel = true;
WindowState = FormWindowState.Minimized;
}
}
private void cmdMinimize_Click(object sender, System.EventArgs e)
{
Close();
}
private void frmOptions_SizeChanged(object sender, System.EventArgs e)
{
if (WindowState == FormWindowState.Normal)
Settings.OptionBounds = ClientSize;
}
protected override void WndProc(ref Message m)
{
// Look for wmquerysession message
if (m.Msg == 0x11)
DOCLOSE = true;
// Call the base.
base.WndProc(ref m);
}
#endregion
 
Back
Top