How to: Create Default Event Handlers on the Windows Forms Designer

Within the Windows Forms Designer, double-clicking the design surface (either the form or a control) creates an event handler for the default action for that item.

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 Working with Settings.

To create the event handler for a default action

  1. Double-click the item on the Windows Forms Designer for which you wish to create a handler.

    The Code Editor opens and the mouse pointer is located inside the newly created default event handler.

  2. Add the appropriate code to the event handler.

    When you finish, your code might look like this:

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    'Add event-handler code here
    End Sub
    
    private void button1_Click(object sender, System.EventArgs e) 
    {
    // Add event-handler code here.
    }
    
    private:
      void button1_Click(System::Object ^ sender,
        System::EventArgs ^ e)
      {
    // Add event-handler code here.
      }
    

    The preceding code is the default event handler for a Button control.

See Also

Tasks

How to: Create Event Handlers Using the Designer

How to: Create Event Handlers at Run Time for Windows Forms

Troubleshooting Inherited Event Handlers in Visual Basic

Concepts

Event Handlers Overview (Windows Forms)

Other Resources

Creating Event Handlers in Windows Forms