Writing event handlers in the development system code window

You have learned to use the VS.NET form design window to lay out the user interface by placing objects on a form, as shown below:

After developing the user interface, you will write your event handlers. You will do that in the code window. Typing Fn7 opens the code window, as shown below (shift Fn7 reopens the design window or you can move between the two using the tabs at the top of the windows):

Note that if you click on the plus sign of the line of Windows Form Designer Generated Code, you see the code that was generated to create the user interface. As we have seen, this code is stored in the .vb file.

If you were going to work on the handler for the event that the user clicks on the object called Button1, you would select it from the list of objects you had defined in the Combo Box at the top-left of the code window.

The Combo Box at the top-right of the code window lists the detectable events Buttons can respond to. Since the handler is for the event that button1 is clicked, you would select the click event.

The development system automatically generates the opening and closing lines of the sub-program that will handle the click on button1 event. You can now type in the instructions the computer will execute when that event occurs.

A shortcut: you can move between the code and design windows by clicking on the tabs at the top of the window.

Another shortcut: you can double click on an object in the form design window to enter the code window with the event handler for that object and its most common event already entered.

Also note that as you type code, the development system often presents you with a list of legal options. You can accept the correct one by hitting the space bar. Microsoft calls this auto-completion feature IntelliSense, and it will cut down on typing time and typing errors.

Finally, you will see several small icons in the code window and documentation. Three of these are (for events), (for methods), and (for properties).


Disclaimer: The views and opinions expressed on unofficial pages of California State University, Dominguez Hills faculty, staff or students are strictly those of the page authors. The content of these pages has not been reviewed or approved by California State University, Dominguez Hills.