UserControl Load event not fired

前端 未结 3 1806
名媛妹妹
名媛妹妹 2020-12-06 20:11

I have WinForms application. My Form derived class has UserControl derived class. I simply put several controls into one UserControl to simplify reuse. The Load

3条回答
  •  情书的邮戳
    2020-12-06 20:16

    There wouldn't be any special properties you need to set for a UserControl's events to fire. You have one of 2 ways to subscribe to the event. In the Properties (property grid) select the events list...double-click at the Load property. All the necessary pieces of code will be put in place, and your cursor will be waiting for you at the proper method.

    The second method is subscribing to the event like so:

    public MyMainForm( )
    {
        InitializeComponents();
        myUserControl.Load += new System.EventHandler(myUserControl_Load);
    }
    
    void myUserControl_Load(object sender, EventArgs e)
    {
        MessageBox.Show(((UserControl)sender).Name + " is loaded.");
    }
    

提交回复
热议问题