coderushforroslyn-119685-static-code-analysis-analyzers-library-crr0028-empty-event-handler.md
This analyzer detects the event handlers that contain no code or throw a NotImplementedException exception. Specify accessibility levels for the event handler methods in the CodeRush options dialog:
The following example demonstrates how the analyzer detects an empty private event handler.
Tip
Use the Highlight unused code in editor check box in the Editor | C# (Visual Basic) | Code Analysis | General option page to enable or disable the highlighting of empty event handler in the code editor.
To fix this issue, add some code to the event handler or delete it along with the subscription statement.
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
Load += Form1_Load;
}
private void Form1_Load(object sender, EventArgs e) {
BackColor = Color.Black;
}
}
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BackColor = Color.Black
End Sub
End Class
Choose Empty event handler in the Editor | C# (Visual Basic) | Code Analysis | Code Issues Catalog options page and check the Enabled checkbox.
See Also