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.
}

 

posted @ 2012-11-06 11:13  webglcn  阅读(990)  评论(0编辑  收藏  举报