Skip to content

winform 初始化顺序问题 #1

@foreachzh

Description

@foreachzh

winform 初始化调用InitializeComponent()时,不会调用Load()函数;我在使用MetroUserControl控件时,在调用InitializeComponent()方法时,会同时调用Load()函数;测试代码如下:
public partial class ucDemo : MetroUserControl{
public object obj = null;
public int nvalue = 0;
public ucDemo()
{ InitializeComponent(); }

     private void ucDemo_Load(object sender, EventArgs e)
    {
        if(obj != null)
           nvalue = 3;
    }

}
////////////////////////////////////////////////////////////////////
public partial class ucDemo : UserControl{
public object obj = null;
public int nvalue = 0;
public ucDemo()
{ InitializeComponent(); }

     private void ucDemo_Load(object sender, EventArgs e)
    {
        if(obj != null)
           nvalue = 3;
    }

}
////////////////////////////////////////////////////////
调用如下:
ucDemo demo = new ucDemo();
demo.obj = new object();
Console.WriteLine(demo.nvalue);
两次的结果应该不一样。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions