Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 15 Adding Graphics and Animation Effects 389


program that includes a separate form with various options to manipulate the photos. You
can make the option form partially transparent so that the user can see any photos beneath
it while still having access to the options.

In the following exercise, you’ll change the transparency of a form by changing the value of
the Opacity property.

Set the Opacity property


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

  2. Create a new Windows Forms Application project named My Transparent Form.

  3. Display the form, click the Button control in the Toolbox, and then draw two buttons
    on the form.

  4. Set the following properties for the two buttons and the form:


Object Property Setting
Button1 Text “Set Opacity”
Button2 Text “Restore”
Form1 Text “Transparent Form”


  1. Double-click the Set Opacity button on the form.

  2. Type the following program code in the Button1_Click event procedure:


Me.Opacity = 0.75
Opacity is specified as a percentage, so it has a range of 0 to 1. This line sets the
Opacity of Form1 (Me) to 75 percent.


  1. Display the form again, double-click the Restore button, and then enter the following
    program code in the Button2_Click event procedure:


Me.Opacity = 1
This line restores the opacity to 100 percent.


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


Tip The complete Transparent Form program is located in the C:\Vb10sbs\Chap15\
Transparent Form folder.


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

Free download pdf