Visual Basic Concepts
Giving Your Control a Transparent Background
Setting the BackStyle property of the UserControl object to Transparent allows whatever is behind your control to be seen, in between the constituent controls on your UserControl's surface. When the BackStyle property is set to Transparent, the BackColor and Picture properties of the UserControl are ignored.
Bitmaps with Transparent Backgrounds
If you assign a bitmap to the UserControl's MaskPicture property, and set the MaskColor property of the UserControl equal to the background color of the bitmap, Visual Basic will clip around the parts of the bitmap that are not equal to the MaskColor — even if those parts are not contiguous.
You can draw on the visible surface of the Bitmap using the graphics methods of the UserControl object, such as Line, Circle, and PaintPicture. Visual Basic will clip your drawing to the visible parts of the bitmap.
Note This feature is supported for image-type bitmaps, such as BMP, GIF, JPEG, and DIB. It is not supported for Windows metafiles, icons, or cursors.
Labels with Transparent BackStyle
If one of the constituent controls on the UserControl is a Label whose BackStyle property has also been set to Transparent, and whose Font property specifies a TrueType font, Visual Basic will clip around the font. In addition, mouse clicks that fall in the spaces between letters will be passed through to the container.
Performance Considerations
Setting BackStyle to Transparent may affect the performance of your control. Visual Basic must do a great deal of clipping to make the background show through correctly if your control uses:
A large number of constituent controls.
A complex bitmap.
A Label control with a transparent background, a TrueType font, and a large amount of text.
To improve the performance of your control, you may be able to create a lightweight user control. The rules for creating controls that are both lightweight and transparent differ somewhat from regular controls. Lightweight user controls are discussed in depth in "Creating Lightweight Controls," later in this chapter.
Note Controls a developer places on a container with a transparent background are not visible. If you want your control to be used as a control container by developers, don't give it a transparent background.