Quote:
By default, controls do not support transparent backcolors. However, you can allow your control to have a background color that is opaque, transparent, or partially transparent by using the SetStyle method[^] in the constructor. The SetStyle
method of the Control class allows you to set particular style preferences for your controls, and can be used to enable or disable support for transparent backcolors.
NoteNote
Note:
Windows Forms controls do not support true transparency. The background of a transparent Windows Forms control is painted by its parent.
To give your control a transparent backcolor
Locate the constructor for your control class. The constructor appears in the control's code file. In C#, the constructor is the method with the same name as the control and with no return value. In Visual Basic, the constructor is the method named New.
Call the SetStyle method of your form in the constructor
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Source:
How to: Give Your Control a Transparent Background[
^]
[EDIT]
Due to
SetStyle
accessibility (
protected method[
^]), the only way to create transparent
Control
(in this case
Label
) is to create custom class which
derives[
^] from
Control
(or
Label
), for example:
Public Class TransparentLabel
Inherits Label
Public Sub New
Me.ForeColor = Color.Green
Me.BorderStyle = 1 'Solid. The border is centered on the edge of the shape.
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
End Sub
End Class
Then, you have to create custom controls in code:
Dim tl As TransparentLabel = New TransparentLabel()
With tl
.Location = New System.Drawing.Point(10, 10)
.Parent = Me
End With
Note: not tested (haven't enough time).