The requested page is not available for the requested platform. You are viewing the content for Default platform.

Declare Event

Declares an event for an undeclared reference.

Availability

From the context menus or via shortcuts:

  • when the edit cursor or caret is on an undeclared event name to the left of the += operator, provided that the right part of the statement contains a new delegate creation.

Example

class TestClass
{
    public void TestMethod()
    {MyEvent += new MyEventHandler(ProcessMyEvent);
    }
    private void ProcessMyEvent(string message)
    {
        Console.WriteLine(message);
    }
    public delegate void MyEventHandler(string message);
}
Public Class TestClass
    Public Sub TestMethod()MyEvent += New MyEventHandler(ProcessMyEvent)
    End Sub
    Private Sub ProcessMyEvent(sender As Object, e As EventArgs)
        Console.WriteLine("processing MyEvent");
    End Sub
    Public Delegate Sub MyEventHandler(message As String)
End Class

Result:

class TestClass
{
    public event TestClass.MyEventHandler MyEvent;
    public void TestMethod()
    {
        MyEvent += new MyEventHandler(ProcessMyEvent);
    }
    private void ProcessMyEvent(string message)
    {
        Console.WriteLine(message);
    }
    public delegate void MyEventHandler(string message);
}
Public Class TestClass
    Public Event MyEvent As CodeProvidersTestVB.TestClass.MyEventHandler
    Public Sub TestMethod()
        MyEvent += New MyEventHandler(ProcessMyEvent)
    End Sub
    Private Sub ProcessMyEvent(sender As Object, e As EventArgs)
        Console.WriteLine("processing MyEvent");
    End Sub
    Public Delegate Sub MyEventHandler(message As String)
End Class