gpt4 book ai didi

vb.net - 如何设置表单具有透明背景

转载 作者:行者123 更新时间:2023-12-02 02:10:00 30 4
gpt4 key购买 nike

我正在努力让我的表单在 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 实现透明表单。

例如。

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

关于vb.net - 如何设置表单具有透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/518020/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com