如何使用户控件透明 [英] how to make user controls transparent

查看:27
本文介绍了如何使用户控件透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 userControl 从 vb6 迁移到 vb.net,但我对其透明度有疑问.在 vb6 中,属性 backstyle 用于使控件透明,但在 vb.net 中,我找不到它.这个属性有什么等价物吗?

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?

推荐答案

在网上搜了几下我发现了这颗珍珠:

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.

这篇关于如何使用户控件透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆