Export (0) Print
Expand All

How to: Create Event Handlers Using the Designer

In nearly all applications, it is essential to respond to user or system events. You can create event handlers using the Properties window, as discussed in the following procedure. For more information about creating default-named event handlers, see How to: Create Default Event Handlers on the Windows Forms Designer.

Note 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 Customizing Development Settings

To create an event handler on the Windows Forms designer

  1. Click the form or control that you want to create an event handler for.

  2. In the Properties window, click the Events button (Events Button).

  3. In the list of available events, click the event that you want to create an event handler for.

  4. In the box to the right of the event name, type the name of the handler and press ENTER.

    Note Note

    Name the event handler according to the functionality of the event; for example, for theClick event, you can typeStartProcess as the event handler.

    The Code Editor appears, showing the code for the form, and an event handler method is generated in your code similar to that shown in the following code example.

    private void StartProcess(object sender, System.EventArgs e) 
       // Add event handler code here.
  5. Add the appropriate code to the event handler.

© 2014 Microsoft