I wanted to hide the main window of my app on startup, so I put this in the constructor:
this.Hide();
This doesn't hide my form though. It seems like I can only get buttons to hide the form. Am I doing something wrong here?
I wanted to hide the main window of my app on startup, so I put this in the constructor:
this.Hide();
This doesn't hide my form though. It seems like I can only get buttons to hide the form. Am I doing something wrong here?
You can start a form hidden using Form.Hide():
Form2 form = new Form2();
//Start Form2 hidden
form.Hide();
//Close Form2
form.Close();
You can create a firstOpen bool variable in the form and make this in the Show event
private void Form1_Shown(object sender, EventArgs e)
{
if (firstOpen)
{
this.WindowState = FormWindowState.Minimized;
Hide();
notifyIcon1.Visible = true;
}
firstOpen = false;
}
In the first time it is showed, it will be hidded. Next time will works normal.
To hide forms on start up, it's actually very simple. You may create the form and store it in a local variable, and simply does not put the form in Application.Run() so that it is not rendered on startup:
Form1 form = new Form1();
Application.Run();
Øyvind is right on that calling this.Hide() from the constructor would not work because the form is not ready yet. In this way, since the form is already created, you may call this.Show() in any function of the form, and call this.Hide() if you want to hide it.