Winforms user controls custom events

前端 未结 2 2053
灰色年华
灰色年华 2020-12-08 10:50

Is there a way to give a User Control custom events, and invoke the event on a event within the user control. (I\'m not sure if invoke is the correct term)

p         


        
2条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 11:33

    Aside from the example that Steve posted, there is also syntax available which can simply pass the event through. It is similar to creating a property:

    class MyUserControl : UserControl
    {
       public event EventHandler TextBoxValidated
       {
          add { textBox1.Validated += value; }
          remove { textBox1.Validated -= value; }
       }
    }
    

提交回复
热议问题