How to: Create Event Handlers in the Visual C# Code Editor (C# Programming Guide)
The Visual C# Code Editor provides an easy way to create event handlers for your Windows Forms while working in design mode. The alternative is to view the code in Source view and add the event handler in code.
Note
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.
To create an event handler using the Visual C# Code Editor
If the Properties Window is not visible, in Design view, right-click on the form or control for which you want to create an event handler, and select Properties.
On top of the Properties Window, click on the Events button.
Double-click the event that you wish to create, for example the Load event.
Visual C# creates an empty event handler method and adds it to your code. Alternatively you can add the code by hand in Code view. For example the following lines of code declare a load event handler for a Form class called
Form1
.private void Form1_Load(object sender, System.EventArgs e) { // Add your form load event handling code here. }
See Also
Concepts
C# Programming Guide
Events (C# Programming Guide)
Delegates (C# Programming Guide)
Editing Code (Visual C#)