C# event with custom arguments

前端 未结 7 1531
庸人自扰
庸人自扰 2020-12-05 09:29

I want to have an event that takes an enum only as the argument. For example

public enum MyEvents{
   Event1
}

// how do I declare this to take enum MyEvent         


        
7条回答
  •  清歌不尽
    2020-12-05 10:08

    You need to declare a custom eventhandler.

    public class MyEventArgs: EventArgs
    {
      ...
    }
    
    public delegate void MyEventHandler(object sender, MyEventArgs e);
    
    public class MyControl: UserControl
    {
      public event MyEventHandler MyEvent;
       ...
    }
    

提交回复
热议问题