Expanding and Shrinking Objects While a Program Is Running


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

  1. On the File menu, click the Close Project command.

  2. Create a new project named My Zoom In.

  3. 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.

  4. Set the following properties for the picture box and the form. When you set the properties for the picture box, note the current values in the Height and Width properties within the Size property. (You can set these at design time, too.)

    Object

    Property

    Setting

    PictureBox1

    Image

    SizeMode

    “c:\vb05sbs\chap15\earth.ico”

    StretchImage

    Form1

    Text

    “Approaching Earth”

  5. Double-click the PictureBox1 object on the form.

    The PictureBox1_Click event procedure appears in the Code Editor.

  6. Type the following program code in the PictureBox1_Click event procedure:

    PictureBox1.Height = PictureBox1.Height + 15 PictureBox1.Width = PictureBox1.Width + 15

  7. These two lines increase the height and width of the Earth icon by 15 pixels each time the user clicks the picture box. If you stretch your imagination a little, watching the effect makes you feel like you're approaching Earth in a spaceship.

  8. Click the Save All button, and then save the project in the c:\vb05sbs\chap15 folder.

    TIP
    The complete Zoom In program is located in the c:\vb05sbs\chap15\zoom in folder.

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

    The Earth icon appears alone on the form, as shown here:

    graphic

  10. Click the Earth icon several times to expand it on the screen.

    After 10 or 11 clicks, your screen looks similar to this:

    graphic

  11. When you get close enough to establish a standard orbit, click the Close button to quit the program.

    The program stops, and the development environment returns.



Microsoft Visual Basic 2005 Step by Step
Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))
ISBN: B003E7EV06
EAN: N/A
Year: 2003
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net