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
Make the form's background to transparent
提问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 BackColor
to Transparent
but I'm getting an error saying Property value is not vald
我制作了一个无边框表单,并将我的背景图像(PNG 格式)设置为如下图所示的图像。我想要的是使表单的背景透明,以便只显示圆形图像。我试图改变形式是BackColor
对Transparent
,但我得到一个错误说Property value is not vald
回答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 TransparencyKey
attribute 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