vb.net 使表单的背景透明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21798859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 17:25:35  来源:igfitidea点击:

Make the form's background to transparent

vb.nettransparencyborderless

提问by elvinguitar

I made a borderless form and I set my background image (in PNG format) to something like the one shown in the image below. What I want is to make the form's background transparent so that only the circular image is shown. I tried changing the form's BackColorto Transparentbut I'm getting an error saying Property value is not vald

我制作了一个无边框表单,并将我的背景图像(PNG 格式)设置为如下图所示的图像。我想要的是使表单的背景透明,以便只显示圆形图像。我试图改变形式是BackColorTransparent,但我得到一个错误说Property value is not vald

image

图片

回答by Manik G

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

         Me.TransparencyKey = Color.LightBlue
         Me.BackColor = Color.LightBlue

    End Sub

回答by aksu

If the background color to transparent work, you could set TransparencyKeyattribute to yur form to make the white color transparent.

如果背景颜色为透明工作,您可以将TransparencyKey属性设置为您的表单以使白色透明。

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.TransparencyKey = Color.White 'if this doesn't work you try:
   'Me.TransparencyKey = Me.BackColor
End Sub

回答by Vignesh Kumar A

Try this

尝试这个

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.BackColor = Color.Transparent
End Sub

(or)

(或者)

Call the SetStyle method of your form in the constructor.

在构造函数中调用表单的 SetStyle 方法。

SetStyle(ControlStyles.SupportsTransparentBackColor, True)

回答by Manik G

   Public Class Form1
Private _InitialStyle As Integer
<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> Public Structure MARGINS
    Public LeftWidth As Integer
    Public RightWidth As Integer
    Public TopHeight As Integer
    Public Buttomheight As Integer
End Structure

<Runtime.InteropServices.DllImport("dwmapi.dll")>
Public Shared Function DwmExtendFrameIntoClientArea(ByVal hWnd As IntPtr, ByRef pMarinset As MARGINS) As Integer
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   'TODO: This line of code loads data into the 'DataSet1.MainMenuMaster' table. 'You can move, or remove it, as needed.
   Try
        Me.BackColor = Color.DarkBlue
        Dim margins As MARGINS = New MARGINS
        margins.LeftWidth = -1
        margins.RightWidth = -1
        margins.TopHeight = -1
        margins.Buttomheight = -1
        Dim result As Integer = DwmExtendFrameIntoClientArea(Me.Handle, margins)
    Catch ex As Exception
        Application.Exit()
    End Try
End Sub

End Class

回答by user5019346

Label1.BackgroundColor = color.FromArgb(25, color.blue)

回答by KRIPS

You can try like, set form's properties from designing side

您可以尝试从设计方面设置表单的属性

back color=system>active-caption and set transparency >active-caption

back color=system>active-caption 并设置透明度>active-caption

and write following code in to the form constructor or activated event:

并将以下代码写入表单构造函数或激活的事件:

 SetStyle(ControlStyles.SupportsTransparentBackColor, True)
 Me.BackColor = Color.Transparent

You can also this video : https://www.youtube.com/watch?v=CEuxm-FV-cU

您也可以观看此视频:https: //www.youtube.com/watch?v=CEuxm-FV-cU