Question

I've create a WinForms control that inherits from System.Windows.Forms.UserControl...I've got some custom events on the control that I would like the consumer of my control to be able to see. I'm unable to actually get my events to show up in the Events tab of the Properties window during design time. This means the only way to assign the events is to programmatically write

myUserControl.MyCustomEvent += new MyUserControl.MyCustomEventHandler(EventHandlerFunction);

this is fine for me I guess but when someone else comes to use my UserControl they are not going to know that these events exist (unless they read the library doco...yeah right). I know the event will show up using Intellisense but it would be great if it could show in the properties window too.

Was it helpful?

Solution

Make sure your events are exposed as public. For example...

[Browsable(true)]
public event EventHandler MyCustomEvent;

OTHER TIPS

A solution using delegate. For example i used for a custom ListView which handle item added event : Declare your delegate :

   public delegate void ItemAddedHandler(object sender, ItemEventArgs e)

then declare the event which use the delegate :

   [Browsable(true)]
   public event ItemAddedHandler ItemAdded;

Note : ItemEventArgs is a custom EventArgs

Hope can help you, works fine for me

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top