Delegate Events

This is a C # question. I have a user control A. A contains another user control B. B has an event called BEvent. I want to expose this event in A, so anyone using A control can subscribe to BEvent. How to write code to implement this project? Thanks.

+4
source share
1 answer

Inside your user control A, you can set the control event B to be like this ...

public event EventHandler EventA { add { _control.EventB += value; } remove { _control.EventB -= value; } } 

You should look at the delegate which event B is using and ensure that event A is consistent. In this example, I just selected an EventHandler because it is quite common when developing custom controls

 public delegate void EventHandler(object sender, EventArgs e); 
+7
source

All Articles