Declare Event Handler

Generates an event handler for the selected method reference with default parameters.

Availability

Available from the context menu or via shortcuts:

  • when the caret is on a statement calling an undeclared event handler.

Example

public class MainWindow : Form
{
    public MainWindow()
    {
        Click += new EventHandler(MainWindow_Click);
    }
}
Public Class MainWindow
    Inherits Form
    Public Sub MainWindow()
        Click += New EventHandler(MainWindow_Click)
    End Sub
End Class

Result:

public class MainWindow : Form
{
    private void MainWindow_Click(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }
    public MainWindow()
    {
        Click += new EventHandler(MainWindow_Click);
    }
}
Public Class MainWindow
    Inherits Form
    Private Sub MainWindow_Click(ByVal sender As Object, ByVal e As EventArgs)
        Throw New NotImplementedException()
    End Sub
    Public Sub MainWindow()
        Click += New EventHandler(MainWindow_Click)
    End Sub
End Class

Animation

rsDeclareEventHandler