Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 15 Adding Graphics and Animation Effects 387


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 .) Since this is an image from space, we’re using a black background for the form,
and a JPEG image of stars in the background. These two form properties, BackColor
and BackgroundImage, are being introduced for the first time in this chapter.

Object Property Setting
PictureBox1 Image
SizeMode

“C:\Vb10sbs\Chap15\Earth .jpg”
StretchImage
Form1 Text
BackColor
BackgroundImage

“Approaching Earth”
Black
“C:\Vb10sbs\Chap15\Space .jpg”

Your form looks like this:


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


The PictureBox1_Click event procedure appears in the Code Editor.


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


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


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

  2. Click the Save All button, and then save the project in the C:\Vb10sbs\Chap15 folder.

Free download pdf