我正在努力让我的表单在 vb.net 中具有透明背景
目前采用新我设置的形式
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, true)
但表单仍然显示为具有默认的灰色背景
有人可以帮忙吗?
编辑:我需要表单上的控件可见,所以我认为将不透明度设置为 0 不起作用
编辑:我尝试了透明度键解决方案,但它不起作用。我有一个黑色背景的圆形图像。 OnPaint 我将透明度键设置为 0,0 处的 img 像素,然后这给我留下了圆形图像(我想要的)它隐藏了黑色背景,但我仍然保留了表单的默认灰色矩形。
下面是我的代码 -
Public Sub New()
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.BackColor = Color.Transparent
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.Timer1.Start()
End Sub
Private Sub frmWoll_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim img As Bitmap = CType(Me.BackgroundImage, Bitmap)
img.MakeTransparent(img.GetPixel(2, 2))
Me.TransparencyKey = img.GetPixel(2, 2)
End Sub
使用 TransparencyKey 实现透明表单。
eg.
TransparencyKey = Color.Red
Button1.BackColor = Color.Red
现在运行该表单,您会发现button1 上有一个洞。
因此,使用此方法,您可以在绘画中创建一个蒙版图像,其中部分必须是透明的,并将该图像应用于表单,瞧,表单现在是透明的。
编辑:
抱歉回复晚了。
以下是您修改后的代码以满足您的要求
Public Sub New()
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.BackColor = Color.Transparent
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Dim img As Bitmap = CType(Me.BackgroundImage, Bitmap)
'img.MakeTransparent(img.GetPixel(2, 2))
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.TransparencyKey = img.GetPixel(2, 2)
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)