Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make user controls transparent

I have migrated a userControl from vb6 to vb.net, and i have problem with it's transparency. in vb6, the property backstyle was used to make the control transparent, but in vb.net, i can't find it. is there any equivalent for this property?

like image 925
Amal Avatar asked Dec 02 '25 00:12

Amal


1 Answers

After some searches on the internet I found this pearl:

Protected Overrides ReadOnly Property CreateParams() As CreateParams
    Get
        ' Make background transparent
        Dim cp As CreateParams = MyBase.CreateParams
        cp.ExStyle = cp.ExStyle Or &H20
        Return cp
    End Get
End Property

Protected Overrides Sub OnPaintBackground(e As PaintEventArgs)
    '' call MyBase.OnPaintBackground(e) only if the backColor is not Color.Transparent
    If Me.BackColor <> Color.Transparent Then
        MyBase.OnPaintBackground(e)
    End If
End Sub

I've tested it and it seems to be working fine.

like image 61
Zohar Peled Avatar answered Dec 03 '25 23:12

Zohar Peled



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!