Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why isn't this.Hide() working in Form1_load event?

Tags:

c#

I have actually one classic Windows form and one button. I have this code

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

    private void button1_Click(object sender, EventArgs e)
    {
        this.Hide();
    }

I would like to know why isn't form hidden just after it is being loaded but works when I click on that button? Can somebody explain it?

like image 449
genesis Avatar asked Aug 09 '11 22:08

genesis


2 Answers

The Load event fires before the form is actually visible. Try using the Form.Shown event. This will fire when the form is actually painted on-screen.

like image 65
Daniel Walker Avatar answered Oct 26 '22 10:10

Daniel Walker


Because you're calling Hide() before the form is shown.

http://msdn.microsoft.com/en-us/library/86faxx0d.aspx

like image 42
Code Magician Avatar answered Oct 26 '22 08:10

Code Magician