One Step Further: Changing Form Transparency


One Step Further: Changing Form Transparency

Interested in one last special effect? With GDI+, you can do things that are difficult or even impossible in earlier versions of Visual Basic. For example, you can make a form partially transparent so that you can see through it. Let's say you're designing a photo-display 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 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”

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

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

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

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

    TIP
    The complete Transparent Form program is located in the c:\vb05sbs\chap15\transparent form folder.

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

  10. Click the Set Opacity button.

    Notice how you can see through the form, as shown here:

    graphic

  11. Click the Restore button.

    The transparency effect is removed.

  12. When you're done testing the transparency effect, 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