|
This project uses a series of eight images that will be "flipped" (placed one after another) in an image box. You will place the 8 images on the form and make them invisible. They will be placed, one after another, in another image box. The eight images will be stored in an array called imgMoon(). The cycling of each image is controlled by a timer control. The Start Button (called cmdStartStop) turns the timer on or off and toggles the caption from "Start" to "Stop" and back. Below are seven images found on the web.
Step 1: Design the Form The form will consist of a 8 image boxes. Seven of the boxes will contain the moon graphics shown above. Each image box will be invisible (that is, the visible property is set to False). These images will be stored in a control array (an array of controls). This will allow each to have the same name (imgMoon) but different indices (0 - 7). The last image box will contain the moon being show (imgCurrentMoon). To design the form, first copy each of the graphic above into the project folder. To create a control array:
The correct response is Yes, you want a control array. Now add 5 more image controls, naming them all imgMoon. VB now understands what you are doing, so it will not ask again. You should now have seven imgMoon images, numbered imgMoon(0) through imgMoon(6). Now add an additional image and name it imgCurrentMoon. You also need a timer and two command buttons. Place imgCurrentMoon in the middle of the form and put the other images off to the side. Remember, they will be invisible when the program runs. The form looks like this:
Step 2: Set the Properties
The form should looks something like this.
When you run the program, the control array is invisible (like the timer!)
Step 3: Write the Code To keep track of which moon is displayed, we need a Global Variable (CurrentMoon) (Declare as integer in general declarations.) Pseudocode for StartStop button if the timer is on
else
Pseudocode for the Timer place current moon into current image box if the current moon index is > 7 then
Pseudocode for Form Load
To make your project more realistic, change the background color of the form to black. Homework For homework, you will use the skills you learned in both the Pong and Moon programs. Start your moon on the left hand border of the form. When the Start button is clicked, the moon should move slowly across the screen. When it hits the right edge of the form, it should reverse course! Of course, it should change phases as it moves!
|