Alex Rivera | Logout

this.Visible is not working in Windows Forms

Asked 2010-09-18T17:30:46.373
23

I have a problem. I need to hide my window at window load. But

private void Form1_Load(object sender, EventArgs e)
{
    this.Visible = false;
}

is not working. And property Visible remains true. Am I missing something?

Edit
Report

2 Answers

10

It seems you can use the following:

private void Form1_Load(object sender, EventArgs e)
{
    this.Opacity = 0;
    this.ShowInTaskbar = false;
}

I just tested it in a winforms app and it worked.

(Also just found this: Single Form Hide on Startup)

answered 2010-09-18T17:56:51.803
2

I think it is not good idea to set visibility from form's Load event. Instead, I would do it by add a public method:

public void LoadForm(...)
{
   // do the all the initializations
}

and call the method to load the form. The form should be not visible unless you explicitly show it:

MyForm instance = new MyForm();
instance.LoadForm(...);
// instance.Show(); or ShowDialog() for dialog form not sure exactly the syntax.
answered 2010-09-18T17:39:19.830

Your Answer