Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 15 Adding Graphics and Animation Effects 385


So long as the timer is enabled, this If... Then decision structure is executed every
75 milliseconds. The first line in the procedure checks whether the GoingUp Boolean
variable is set to True, indicating that the icon is moving toward the top of the form.
If it’s set to True, the procedure moves the picture box object to a relative position
10 pixels closer to both the top and left edges of the form.
If the GoingUp variable is currently set to False, the decision structure moves the icon
down instead. In this case, the picture box object moves until the edge of the form
is detected. The height of the form can be determined by using the Me.Size.Height
property. (I subtract 75 from the form height so that the icon is still displayed on the
form .) The Me object in this example represents the form (Form1).
As you’ll see when you run the program, this movement gives the icon animation
a steady drifting quality. To make the icon move faster, you decrease the Interval setting
for the timer object. To make the icon move slower, you increase the Interval setting.

Run the Moving Icon program

Tip The complete Moving Icon program is located in the C:\Vb10sbs\Chap15\Moving Icon
folder.


  1. Click the Start Debugging button to run the program.


The Moving Icon program runs in the IDE.


  1. Click the Move Up button.


The picture box object moves up the form on a diagonal path, as indicated here:

After a few moments, the button comes to rest at the upper edge of the form.
Free download pdf