C# 让我的事件显示在属性窗口中

C# 让我的事件显示在属性窗口中,c#,visual-studio,visual-studio-2008,C#,Visual Studio,Visual Studio 2008,我正在制作一个自定义列表框(用于紧凑型框架) 我做了一件事。我想知道如何让我的自定义事件显示在VisualStudio属性窗口的事件列表中 我正在使用C#和Visual Studio 2008 下面是我的班级参加活动的一个例子: class OwnerDrawnListBox<T> : System.Windows.Forms.Control { // Other List Box things public DrawItemEventHandler DrawIte

我正在制作一个自定义列表框(用于紧凑型框架)

我做了一件事。我想知道如何让我的自定义事件显示在VisualStudio属性窗口的事件列表中

我正在使用C#和Visual Studio 2008

下面是我的班级参加活动的一个例子:

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

    public DrawItemEventHandler DrawItemEventHandler { get; set; }

    public OwnerDrawnListBox()
    {
       // ListBox init stuff
    }

    // Other ListBox Stuff
}
class OwnerDrawnListBox:System.Windows.Forms.Control
{
//其他列表框内容
公共DrawItemEventHandler DrawItemEventHandler{get;set;}
公有人DrawnListBox()
{
//listboxinit内容
}
//其他列表框内容
}

示例中的代码没有创建事件,而是创建了属性。您需要使用
事件
关键字:

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

    public event DrawItemEventHandler DrawItemEventHandler;

    public OwnerDrawnListBox()
    {
       // ListBox init stuff
    }

    // Other ListBox Stuff
}
class OwnerDrawnListBox:System.Windows.Forms.Control
{
//其他列表框内容
公共事件DrawItemEventHandler DrawItemEventHandler;
公有人DrawnListBox()
{
//listboxinit内容
}
//其他列表框内容
}

如果它没有立即显示在属性网格中,则可能需要重建项目。此外,您可能需要考虑重命名您的事件以使其没有与委托名称相同的名称(删除“EvEnthANDER”位或称之为“ItDigDRAW”)。

< P>您的示例中的代码不创建事件,您创建了一个属性。您需要使用
事件
关键字:

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

    public event DrawItemEventHandler DrawItemEventHandler;

    public OwnerDrawnListBox()
    {
       // ListBox init stuff
    }

    // Other ListBox Stuff
}
class OwnerDrawnListBox:System.Windows.Forms.Control
{
//其他列表框内容
公共事件DrawItemEventHandler DrawItemEventHandler;
公有人DrawnListBox()
{
//listboxinit内容
}
//其他列表框内容
}
如果它没有立即显示在属性网格中,则可能需要重建项目。此外,您可能需要考虑重命名您的事件以使它没有与委托名称相同的名称(删除“EvEnthDANLER”位)或称之为“ItMaDigice”之类的东西。