如何使用户控件透明
how to make user controls transparent
我已将 userControl 从 vb6 迁移到 vb.net,但我对它的透明度有疑问。
在 vb6 中,属性 backstyle 用于使控件透明,但在 vb.net 中,我找不到它。
这个属性有什么等价物吗?
在网上搜索后,我找到了这颗珍珠:
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
我已经测试过了,它似乎工作正常。
我已将 userControl 从 vb6 迁移到 vb.net,但我对它的透明度有疑问。 在 vb6 中,属性 backstyle 用于使控件透明,但在 vb.net 中,我找不到它。 这个属性有什么等价物吗?
在网上搜索后,我找到了这颗珍珠:
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
我已经测试过了,它似乎工作正常。