我制作了一个无边框表格,然后将背景图像(PNG格式)设置为如下图所示。我想要的是使表单的背景透明,以便只显示圆形图像。我尝试将表单的BackColor
更改为Transparent
但是我收到一个错误说Property value is not vald
试试这个
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.BackColor = Color.Transparent
End Sub
(要么)
在构造函数中调用表单的SetStyle方法。
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.TransparencyKey = Color.LightBlue
Me.BackColor = Color.LightBlue
End Sub
如果背景颜色为透明工作,则可以将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
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
Label1.BackgroundColor = color.FromArgb(25, color.blue)
您可以尝试,从设计方面设置表单的属性
back color = system> active-caption和set transparency> active-caption
并将以下代码写入表单构造函数或激活事件:
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.BackColor = Color.Transparent