如何将表单设置为具有透明背景

Dea*_*ean 6 vb.net winforms

我很难让我的表单在vb.net中拥有透明的背景

目前以New I的形式设置

Me.SetStyle(ControlStyles.SupportsTransparentBackColor, true) 
Run Code Online (Sandbox Code Playgroud)

但是表单仍然显示为具有默认的灰色背景

谁能帮忙?

编辑:我需要窗体上的控件可见,所以我不认为将不透明度设置为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
Run Code Online (Sandbox Code Playgroud)

Sac*_*van 12

使用TransparencyKey获取透明表单.

例如.

TransparencyKey = Color.Red
Button1.BackColor = Color.Red
Run Code Online (Sandbox Code Playgroud)

现在运行表单,你会发现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
Run Code Online (Sandbox Code Playgroud)