我创建了一个无边框表单,然后将背景图像(PNG格式)设置为如下图所示。我想要的是使表单的背景透明,以便只显示圆形图像。我尝试将表单BackColor
更改为Transparent
但我收到错误Property value is not vald
答案 0 :(得分:6)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.TransparencyKey = Color.LightBlue
Me.BackColor = Color.LightBlue
End Sub
答案 1 :(得分:3)
如果背景颜色为透明效果,则可以将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
答案 2 :(得分:1)
试试这个
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.BackColor = Color.Transparent
End Sub
(或)
在构造函数中调用表单的SetStyle方法。
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
答案 3 :(得分:0)
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
答案 4 :(得分:0)
Label1.BackgroundColor = color.FromArgb(25, color.blue)
答案 5 :(得分:0)
你可以试试, 从设计方面设置表格的属性
back color = system&gt; active-caption 并设置透明度&gt; active-caption
并将以下代码写入表单构造函数或激活事件:
#HoverMe
您还可以观看以下视频:https://www.youtube.com/watch?v=CEuxm-FV-cU