Lab 2
comp 125-609, Goldwasser
Tuesday, September 7, 1999

Purpose: To get some experience writing Event Handlers, and to learn specifically about events involving the changing focus and clicking on controls.

Our goal for this lab is to design a simple stop light which can be controlled manually by the user. The program window should involve four picture boxes, one which acts as the backdrop for the lights, and then three rectangular lights on top of this backdrop which will be used for the red, yellow and green lights.

Your program should have the following functionality,

  • The program should start with the green light on
  • Whenever the user clicks on a light, that light should be turned on (and all others turned off)
  • Whenever the user presses the tab key, your program should switch the currently displayed light to the next color, following the cyclical order green -> yellow -> red -> green.
  • A sample of a working program can be downloaded from,
    www.math.luc.edu/~mhg/comp125/labs/sampLab2.exe

    Advice:

    At run time, your program code can assign colors by referring to the predefined color constants: vbRed, vbYellow, vbGreen, vbBlack, among others. (See page 58, Comment 7 for a full list)

    This program will involve use of some/all of the event handlers Click(), LostFocus(), and GotFocus(). When a program executes, the "Tab" key switches the focus from the current object to the next, where the default cyclical order is based on the order in which the objects were created.

    To remove an object from this cyclical order (e.g. the backdrop), you may set the "TabStop" property to "False". Please note, such an object is still allowed to receive the focus -- it just won't be given the focus ever by way of the Tab key. To complete disable an object from receiving the focus or from receiving any events, set the "Enabled" property to "False".

    When testing your program, you should assure the following:

  • There should always be one light turned on
  • There should never be more than one light on at a time
  • By manually clicking, the user can make the lights go on in any desired order
  • After manually clicking to turn a particular light on, if the user resumes by hitting the tab key, the next light displayed should indeed be the correct one in the standard cyclical order.

  • This lab is due before leaving class today. When you have completed the program you should do the following:
  • (1) Print out your project as follows. Click "File". Click "Print". In the Range box, select "Current project". In the Print What box, click on all three of "Form Image", "Code" and "Form as Text".
  • (2) Please call me over to your computer to run your program and to turn in your printout.