Chapter 6 Using Decision Structures 177
- Click the Quit button to stop the program.
The program stops, and the development environment returns.
You’ve finished working with If... Then and Select Case decision structures in this chapter.
You’ll have several additional opportunities to work with them in this book, however.
If... Then and Select Case are two of the crucial decision-making mechanisms in the Visual
Basic programming language, and you’ll find that you use them in almost every program that
you write.
One Step Further: Detecting Mouse Events
I began this chapter by discussing a few of the events that Visual Basic programs can respond
to, and as the chapter progressed, you learned how to manage different types of events by
using the If... Then and Select Case decision structures. In this section, you’ll add an event
handler to the Select Case program that detects when the pointer “hovers” over the Country
list box for a moment or two. You’ll write the special routine, or event handler, by building
a list box event procedure for the MouseHover event, one of several mouse-related activities
that Visual Basic can monitor and process. This event procedure will display the message
“Please click the country name” if the user points to the country list box for a moment or
two but doesn’t make a selection, perhaps because he or she doesn’t know how to make
a selection or has become engrossed in another task.
Add a mouse event handler
- Open the Code Editor if it isn’t already open.
- At the top of the Code Editor just below the Form1 .vb tab, click the Class Name arrow,
and then click the lstCountryBox object. - Click the Method Name arrow, and then click the MouseHover event.
Visual Basic adds the lstCountryBox_MouseHover event procedure in the Code Editor,
as shown here:
Each object on the form has one event procedure that is added automatically
when you double-click the object on the form. When you need to add other event
procedures for an object, you can use the Method Name list box.