When is the form displayed?

I am trying to figure out when an event occurs Form.Load. On MSDN it sais:

Occurs before the form is displayed for the first time.

But when is the form first displayed? My first instinct was right after InitializeComponent(), but when I tried the following code, it MessageBoxshowed 5, although the value was set after InitializeComponent(), so it was not right after InitializeComponent():

public partial class Form1 : Form
{
    private int number;

    public Form1()
    {
        InitializeComponent();

        number = 5;
    }

    public void Form_Load(object sender, EventArgs e)
    {
        MessageBox.Show(number);
    }
}

So, when does this happen?

+4
source share
3 answers

OnLoadis one of the methods called on Showor ShowDialogon Form.

Show ShowDialog OnLoad Load. ( OnHandleCreated ..)

+5
+2

, Windows Forms

, , -. , Form.Load, , ( ) , .

+2

Source: https://habr.com/ru/post/1670998/


All Articles