Hi,
I made some experiments ... and now I have a solution for you.
Perhaps you do some Changes - but it works like you asked ...
Public Class customLabel
Inherits Label
Sub New()
Me.SetStyle(ControlStyles.Opaque, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, False)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Font = New System.Drawing.Font("Microsoft Sans Serif", 28.2!)
End Sub
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20
Return cp
End Get
End Property
Property Opacity As Integer
Get
Return myOpacity
End Get
Set(value As Integer)
If value >= 0 And value <= 255 Then myOpacity = value
Invalidate()
End Set
End Property
Private myOpacity As Integer = 0
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
Dim myBitmap As New Bitmap(Me.Width, Me.Height)
Dim gr As Graphics = Graphics.FromImage(myBitmap)
Dim pBackColor As Color = myBackColor
If myBackColor = Color.Transparent Then
If myParent IsNot Nothing Then pBackColor = myParent.BackColor
End If
Dim pe As New System.Windows.Forms.PaintEventArgs(gr, e.ClipRectangle)
MyBase.OnPaint(pe)
For y As Integer = 0 To Height - 1
For x As Integer = 0 To Width - 1
Dim PixelColor As Color = myBitmap.GetPixel(x, y)
If PixelColor.A <> 0 Then
myBitmap.SetPixel(x, y, Color.FromArgb(myOpacity, PixelColor))
Else
myBitmap.SetPixel(x, y, Color.FromArgb(255, pBackColor))
End If
Next x
Next y
e.Graphics.DrawImage(myBitmap, 0, 0)
End Sub
Private Sub me_HandleCreated(sender As Object, e As System.EventArgs) Handles Me.HandleCreated
myParent = Parent
If myParent IsNot Nothing Then myParent_Enabled = myParent.Enabled
End Sub
Private WithEvents myParent As Control
Overrides Property BackColor As Color
Get
Return myBackColor
End Get
Set(ByVal value As Color)
myBackColor = value
Me.Invalidate()
End Set
End Property
Private myBackColor As Color = Color.Blue
End Class