Events In Visual Basic


Events In Visual Basic

In this article, we will try to study the way a visual basic program interacts with the Windows (OS) environment.

Windows program behaves differently from a DOS-based program. Instead of the program controlling the user, the user controls the program. When the user responds to a menu or control, Windows generates an event that describes the particular action. Let us understand what an event is. This is one of the most fundamental aspect of windows programming. You will find events everywhere, not only in VB but also in Win32 programming.

In Windows terminology, an event is the action that the user takes. Whenever the user clicks the mouse, presses a key, responds to a control, or selects from a menu, an event happens. Windows constantly monitors the running Visual Basic program, looking for events. Too many things can happen in a GUI-based program for it to follow a straight, sequential pattern. In a Windows program, you are offered a selection of controls, and you can respond to any control in any order. The program must be able to sense when an event takes place and to handle it accordingly.

Windows and Visual Basic constantly monitor running programs. When the user clicks a command button or performs any other kind of event, Windows intercepts the event and sends it to Visual Basic. Visual Basic does not respond to some special system events, such as when the user presses Alt+Tab to switch to another application running in memory. That is why Windows must interpret all events and pass the ones handled by Visual Basic to Visual Basic.

The 'look' of a Visual Basic application is determined by what controls are used, but the 'feel' is determined by the events. An event is something which can happen to a control. For example, a user can click on a button, change a text box, or resize a form. As explained in earlier article, writing a program is made up of three events: 1) select suitable controls, 2) set the properties, and 3) write the code. It is at the code writing stage when it become important to choose appropriate events for each control.

Before any events can be coded it is necessary to design the interface from suitable controls. The interface can be deigned using text boxes. Since the purpose of this article is to explain concept of events, I won't go in much details of designing the interface. Once the user interface has been complete, double click on the command button to bring up a code window. Before writing any

The copyright of the article Events In Visual Basic in Learning Visual Basic is owned by Swapna Kamat. Permission to republish Events In Visual Basic in print or online must be granted by the author in writing.

Go To Page: 1 2

Articles in this Topic    Discussions in this Topic