386 Part III Designing the User Interface
Note If you placed the picture box object in the lower-right corner of the form, as
instructed in step 3 of the previous exercise, you see something similar to this screen shot.
However, if you placed the picture box object in another location, or created a smaller
form, the image might drift off the screen when you click Move Up or Move Down. Can
you tell why?
- Click the Move Down button.
The picture box moves back down again to the lower-right corner of the screen.
- Click both buttons again several times, and ponder the animation effects.
Note that you don’t need to wait for one animation effect to end before you click the
next button. The Timer1_Tick event procedure uses the GoingUp variable immediately
to manage your direction requests, so it doesn’t matter whether the picture box has
finished going in one direction. Consider this effect for a moment, and imagine how
you could use a similar type of logic to build your own Visual Basic video games. You
could increase or decrease the animation rates according to specific conditions or
“collisions” on screen, and you could force the animated objects to move in different
directions. You could also change the picture displayed by the picture box object based
on where the icon is on the screen or what conditions it encounters.
- When you’re finished running the program, click the Close button on the form to stop
the demonstration. - Click the Save All button to save the project, and then specify the C:\Vb10sbs\Chap15
folder as the location.
Expanding and Shrinking Objects While a Program Is Running
In addition to maintaining a Top property and a Left property, Visual Basic maintains a Height
property and a Width property for most objects on a form. You can use these properties in
clever ways to expand and shrink objects while a program is running. The following exercise
shows you how to do it.
Expand a picture box at run time
- On the File menu, click the Close Project command.
- Create a new Windows Forms Application project named My Zoom In.
- Display the form, click the PictureBox control in the Toolbox, and then draw a small
picture box object near the upper-left corner of the form. - Set the following properties for the picture box and the form.