Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

380 Part III Designing the User Interface



  1. Click the Close button to end the program.

  2. Click the Save All button on the Standard toolbar to save the project, and then specify
    the C:\Vb10sbs\Chap15 folder as the location.
    Now you’re ready to move on to some simple animation effects.


Adding Animation to Your Programs


Displaying bitmaps and drawing shapes adds visual interest to a program, but for
programmers, the king of graphical effects has always been animation. Animation is the
simulation of movement produced by rapidly displaying a series of related images on the
screen. Real animation involves moving objects programmatically, and it often involves
changing the size or shape of the images along the way.

In this section, you’ll learn how to add simple animation to your programs. You’ll learn how
to update the Top and Left properties of a picture box, control the rate of animation by using
a timer object, and sense the edge of your form’s window.

Moving Objects on the Form


In Visual Studio 2010, a group of special properties named Left, Top, and Location, and the
SetBounds method allow you to move objects in the coordinate system. Table 15-2 offers
a description of these keywords and how they support basic animation effects.

TABLE 15-2 Useful Properties and Methods for Moving Objects on a Form
Keyword Description
Left This property can be used to move an object horizontally (left or right).
Top This property can be used to move an object vertically (up or down).
Location This property can be used to move an object to the specified location.
SetBounds This method sets the boundaries of an object to the specified location and size.

In the following sections, you’ll experiment with using the Left, Top, and Location properties
to move objects.

To move an object in a horizontal direction, use the Left property, which uses the syntax:

object.Left = horizontal

where object is the name of the object on the form that you want to move, and horizontal is
the new horizontal, or x-axis, coordinate of the left edge of the object, measured in pixels.
For example, the following program statement moves a picture box object to a location
300 pixels to the right of the left window edge:

PictureBox1.Left = 300
Free download pdf