Transparent CrystalLabel and CrystalPictureBox

| | Comments (0)

CrystalLabel and CrystalPictureBox were not allowing Transparent backgrounds. This is a bug that was fixed in Crystal Toolkit version 0.77. I have to admit that I am more focused on the gradient properties of these controls--doing the transparency thing was a side experiment. I've been tempted to drop the transparent mode altogether (and I have done that in CrystalTrackBar, which has numerous problems). However, I found a pretty simple fix to allow the Label and PictureBox controls to retain a transparent background.

How do you set these controls to have a Transparent background? By default, you have the gradient mode set when you drag CrystalLabel and CrystalPictureBox onto your form:

gradient_control.jpg

To attain this gradient setting, you need to have BackColor set to Control, and then Color1 and Color2 make up the gradient blend of colors:

gradient_control_setting.jpg

Now, if you want the Transparent background, simply set BackColor to Transparent (on the Web tab of the color property dialog). This is the standard way to set transparency with other .NET controls. When I started this toolkit, I was ignorant of that fact. Internally within the CrystalGraidentControl class, setting BackColor to Transparent makes the TransparentMode property true.

transparent_control_setting.jpg

The end result is that both the CrystalLabel and CrystalPictureBox controls have a transparent background and allow the wallpaper in the form to show through. This sample code is in the CrystalToolkit 0.77, called TestAttilanTransparent.

transparent_control.jpg

Leave a comment