TRANSPARENCY

The Form object provides a couple of properties that you can use to make a form partially transparent. Opacity determines the form’s opaqueness. At design time, the Properties window shows Opacity as a percentage where 100 percent means the form is completely opaque, and 0 percent means that the form is completely transparent. At run time, your program must treat Opacity as a floating-point value between 0 (completely transparent) and 1 (completely opaque).

A program can use an Opacity value less than 100 percent to let the user see what lies below the form. For example, you might build a partially transparent Search dialog box so the user could see the underlying document as a search progresses.

If Opacity is greater than 0 percent, the form behaves normally aside from its ghostlike appearance. The user can click it, interact with its controls, minimize and maximize it, and grab its borders to resize it.

If Opacity is 0 percent, the form is completely transparent and the user can interact with the form only through the keyboard. For example, the user can press the Tab key to move between the form’s controls, type text, press the Spacebar to invoke a button that has the focus, and press Enter or Esc to fire the form’s Accept and Cancel buttons; however, the form and its controls will not detect mouse clicks. The user also cannot see the form (obviously), so figuring out which control has the focus can be next to impossible.


TOO MUCH TRANSLUCENCY
Most applications don’t need translucent forms. A well-designed application allows the user to move windows around so they don’t obscure each other. Translucent forms can be confusing, may create extra confusion for users with special needs, and incur a performance penalty. They’re an interesting special effect but are not generally necessary.

If Opacity is 2 percent, the form is still invisible, but it recognizes mouse clicks, so it can obscure the windows below.

A second property that helps determine the form’s transparency is TransparencyKey. This property is a color that tells Visual Basic which parts of the form should be completely transparent. When the form is rendered, any areas with this color as their background colors are not drawn.

The most common use for TransparencyKey is to create shaped forms or skins. Set the form’s FormBorderStyle property to None to remove the borders, title bar, and system buttons. Set the form’s BackColor and TransparencyKey properties to a color that you don’t want to appear on the form. Then draw the shape you want the form to have in some other color.

Figure 9-1 shows the Smiley example program, which has a form shaped like a smiley face. The form’s TransparencyKey and BackColor properties are both red so the form is transparent. The Paint event handler draws the image on the form. These sorts of forms make interesting splash screens and About dialog boxes, although they are often too distracting for use in a program’s main user interface.

FIGURE 9-1: The TransparencyKey property lets you make shaped forms such as this one.

image

If you use Opacity and TransparencyKey together, pixels that match TransparencyKey are completely removed and any remaining pixels are shown according to the Opacity value.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.146.173