Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event using generic EventHandler<> not visible in Designer

I've just noticed that if I add an event using a generic eventhandler to my UserControl, the event is not visible in the designer when I add the user control to a form.

public event EventHandler<TEventArgs<int>> EventNotVisibleInDesigner;
public event EventHandler EventVisibleInDesigner;

Not particularly worrisome, but is this by-design/normal, or am I doing something wrong?

like image 923
Benjol Avatar asked Feb 26 '23 05:02

Benjol


1 Answers

The Windows Forms designer has limited support for generic types. It will work okay when you avoid the generic type argument for EventHandler<T>:

    public class TEventArgs<T> : EventArgs { }
    public class MyEventArgs : TEventArgs<int> { }
    public event EventHandler<MyEventArgs> EventNowAlsoVisibleInDesigner;
like image 140
Hans Passant Avatar answered Mar 12 '23 10:03

Hans Passant