views:

49

answers:

1

I am making a custom Listbox (for the compact framework).

I have made an event (OnDrawItem). I would like to know how to get my custom event to show up in the event list in the properties window in Visual Studio.

I am using C# and Visual Studio 2008.

Here is an example of my class with the event:

class OwnerDrawnListBox<T> : System.Windows.Forms.Control
{
    // Other List Box things

    public DrawItemEventHandler DrawItemEventHandler { get; set; }

    public OwnerDrawnListBox()
    {
       // ListBox init stuff
    }

    // Other ListBox Stuff
}
+3  A: 

The code in your example does not create an event, you've created a property. You need to use the event keyword:

class OwnerDrawnListBox<T> : System.Windows.Forms.Control
{
    // Other List Box things

    public event DrawItemEventHandler DrawItemEventHandler;

    public OwnerDrawnListBox()
    {
       // ListBox init stuff
    }

    // Other ListBox Stuff
}

If it doesn't show up in the properties grid straight away, you might need to rebuild your project. Also, you might want to consider renaming your event to so that it doesn't have the same name as the delegate name (remove the "EventHandler" bit or call it something like "ItemDrawn").

Rory
That did it! Thanks.
Vaccano