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
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 on the Windows Forms designer
Click the form or control that you want to create an event handler for.
In the Properties window, click the Events button ().
In the list of available events, click the event that you want to create an event handler for.
In the box to the right of the event name, type the name of the handler and press ENTER.
Note
Name the event handler according to the functionality of the event; for example, for the Click event, you can type StartProcess 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 Sub StartProcess(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.Click ' Add event handler code here. End Sub
private void StartProcess(object sender, System.EventArgs e) { // Add event handler code here. }
private void StartProcess(System.Object sender, System.EventArgs e) { // Add Event Handler Code Here }
private: void StartProcess(System::Object ^ sender, System::EventArgs ^ e) { // Add event handler code here. }
Add the appropriate code to the event handler.
See Also
Tasks
How to: Create Default Event Handlers on the Windows Forms Designer
Concepts
Event Handlers Overview (Windows Forms)