使表单的背景变得透明

问题描述 投票:0回答:6

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

vb.net transparency borderless
6个回答
2
投票

试试这个

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

(要么)

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

SetStyle(ControlStyles.SupportsTransparentBackColor, True)

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

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

    End Sub

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

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

0
投票
Label1.BackgroundColor = color.FromArgb(25, color.blue)

0
投票

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

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

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

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

你也可以这个视频:https://www.youtube.com/watch?v=CEuxm-FV-cU

© www.soinside.com 2019 - 2024. All rights reserved.