Hiding forms on startup: why doesn't this.Hide() hide my form?

you can use this line of code. It wont hide it, but it will be minimized:

this.WindowState = FormWindowState.Minimized;

in addition, if you don't want it showing on the task bar either, you can add this line:

this.ShowInTaskbar = false;

But why do you create the form if you don't want it to be visible in the first place?


Just override the OnVisibleChanged method and change the visibility of the form in there, something like this:

protected override void OnVisibleChanged(EventArgs e)
{
    base.OnVisibleChanged(e);
    this.Visible = false;
}

And that's it! Simple and clean.


If you would rather use this.Hide or this.Show you can do this

protected override void OnShown(EventArgs e)
{
    base.OnShown(e);
    this.Hide();
}

Tags:

C#

Forms