winform override onload

// form designer

this.Load += Form1_Load;



// Form1.cs

private void Form1_Load(object sender, EventArgs e)

{

    MessageBox.Show("a");

}



--------------------------------------------------------



if override OnLoad abstract method which is defined in Form class, call base.OnLoad(e) is required, otherwise, this.Load event cannot get called.



// form designer

this.Load += Form1_Load;



// Form1.cs

private void Form1_Load(object sender, EventArgs e)

{

    MessageBox.Show("a");

}



protected override void OnLoad(EventArgs e)

{

    base.OnLoad(e); // if this is commented, event cannot invoke.

}

 

你可能感兴趣的:(override)