Controls Messages and Events |
|
|
2. The Type of Message |
After the sender of a message has been identified, the operating system would need to know:
By convention, the name of the event is written after the name of the object that sent the message. To distinguish between a control's name and its event, Visual Basic uses a convention of displaying an underscore between them, like this: Private Sub MessageSender_Event |
3. The Message Accessories |
Once the operating system knows what object sent the message and what that message is, depending on the message, it may need to know:
While one message may appear easy, such as clicking an object, another message would need additional information such as where (the coordinates of the mouse cursor) the clicking occurred. Therefore, some events will need some values from you. In some situations it will be one value; in this case the accessory is called an argument. Another type of event may need more than one accessory, thus many arguments. Again, depending on the event, this could be one argument, or it could be as many arguments as necessary. When we move on, we will see what events need what argument(s) The argument or group of arguments that the event may need is listed in parentheses on the right side of the event name, like this: Private Sub MessageSender_Event(Argument1, Argument2, Argument_n) Even if an event doesn't need an argument, you must provide empty parentheses, like this: Private Sub MessageSender_Event() |
The Body of an Event |
The subject of the assignment is called the body. It starts with the Private Sub line and ends with a line identified as End Sub. Between these two lines, you specify what the event is supposed to accomplish. Some events just need to know what you want them to do, for example, you can ask a button to close a form when that button is clicked. On the other hand, when the user clicks somewhere on an object, you could ask the object to display something depending on the button the user clicked. In this case, the event code would like to know what button was clicked. The above introduction was meant to show you what a coded event looks like. Microsoft Visual Basic will do a lot of work for you behind the scenes. For example, it will always set a beginning and end event for you. It will also specify the names (and types) of arguments for you. This means that Visual Basic always writes a skeleton code for your event; you can then customize it as you see fit. |
Practical Learning: Starting an Event |
|
Categories of Events |
The Keyboard Events |
Word processing consists of manipulating text and characters on your computer until you get the fantastic result you long for. To display these characters, you press some keys on your keyboard. If the application is configured to receive text, your pressing actions will display characters on the screen. The keyboard is also used to perform various other actions such as accepting what a dialog box displays or dismissing one. When you press the keys
on your keyboard, you are sending keyboard events. |
The Click Event |
The mouse has become a very important object of computer use. It is used by pressing one of its buttons. |
The Double-Click Event |
When you press the left mouse button once, the event is called the Click event. Another action you can perform is to click the button twice but very fast. This is referred to as double-clicking. |
The Right-Click Event |
Since Microsoft Windows 95, the mouse buttons are intensely used and both buttons have become important object of the computer daily use. By default, the users click the left mouse button for all routine work. The other button, the right one, is used in various circumstances, such as displaying a context menu. The Right-Click action is performed by clicking the right mouse button. The actions that the right-clicking produce completely depend on the programmer. When writing code for the right-click button, you will have to find out what button was clicked, and then write code accordingly. |
The Focus Events |
Microsoft Windows operating systems allow you to work on more that one application at the same time. They also allow you to work on many forms as the computer can handle. But only one application can receive instructions at a given time. For example, although you can edit text on a word processor while a spreadsheet is running in the background, you can only perform one action at a time. You have the ability to display the desired application when needed. This applies to applications. Many dialog boxes have more than one input control, such as the Font dialog box we used earlier. Although all these controls are available, you can work from only one control at a time. If many applications are running on your computer while you are working, the program that is currently being edited or receiving input from you is said to have focus. If you have two forms, you can open both of them but at a given time, you can work on only one of them. On a form that is equipped with many controls, only one control can be changed at a time; such a control is said to have focus. The application or the form that has focus usually has its title bar with the active window color as set in Control Panel. In a form with many controls, the one that has focus will usually have a cursor or a dotted line around its selection. When an application, a form, or a control has focus, Microsoft Visual Basic applies the GotFocus event. If the focus shifts to another application, form, or control, Microsoft applies the LostFocus to the same component. |
Launching and Loading A Program |
Your computer is filled with a lot of programs, some of which you use all the time, some of which you use some time to time, and some of which you probably never or rarely use. Since the computer can't predict what you want to do, it keeps all these programs in a storage area called the hard drive. They simply stay there and wait. When you want to use one of these programs, you ask the computer to bring it to you. There is another, temporary, storage area in your computer called the memory (RAM). This is where the computer puts the programs you are using currently. When, you decide to use a program, the computer brings it up. When you have finished using the program, the computer puts it back into the hard drive. Of course, the computer can put as many programs as possible into the memory (or as many as the capacities of the computer allow it). To use a program, you have to "Load" it into memory (the computer will do it for you). And to load a program you have to select and start it. That's why you need to find it and... When a program starts, it is said to be launched. Visual Basic considers that the program is Opening. It takes just a few seconds for a program to launch or open. Some of them display a "Splash Screen" while they are launching. After the program has been launched, it is said to be Loaded. Once a program is loaded, it is said to be running. Actually, loaded and running would mean the same thing, especially in Visual Basic. |
Practical Learning: Loading a Program |
|
|
||
Previous | Copyright © 2002-2005 FunctionX, Inc. | Next |
|