vb.net – 如何设置表单以具有透明背景
发布时间:2020-12-17 00:27:36 所属栏目:大数据 来源:网络整理
导读:我很难让我的表单在vb.net中拥有透明的背景 目前以New I的形式设置 Me.SetStyle(ControlStyles.SupportsTransparentBackColor,true) 但是表单仍然显示为具有默认的灰色背景 谁能帮忙? 编辑:我需要窗体上的控件可见,所以我不认为将不透明度设置为0将起作用
我很难让我的表单在vb.net中拥有透明的背景
目前以New I的形式设置 Me.SetStyle(ControlStyles.SupportsTransparentBackColor,true) 但是表单仍然显示为具有默认的灰色背景 谁能帮忙? 编辑:我需要窗体上的控件可见,所以我不认为将不透明度设置为0将起作用 编辑:我尝试了透明度密钥解决方案,但它不起作用.我有一个黑色背景的圆形图像. OnPaint我将透明度键设置为0,0的img像素,然后这给我留下了圆形图像(我想要的)它隐藏了黑色背景,但我仍然保留了表单的默认灰色矩形. 下面是我的代码 – Public Sub New() Me.SetStyle(ControlStyles.SupportsTransparentBackColor,True) Me.BackColor = Color.Transparent ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Me.Timer1.Start() End Sub Private Sub frmWoll_Paint(ByVal sender As Object,ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim img As Bitmap = CType(Me.BackgroundImage,Bitmap) img.MakeTransparent(img.GetPixel(2,2)) Me.TransparencyKey = img.GetPixel(2,2) End Sub
使用TransparencyKey获取透明表单.
例如. TransparencyKey = Color.Red Button1.BackColor = Color.Red 现在运行表单,你会发现button1中有一个洞. 因此,使用此方法,您可以在绘制中创建一个掩模图像,其中部分必须是透明的,并将该图像应用于表单,并且表单现在是透明的. 编辑: 以下是您的代码修改,以满足您的要求 Public Sub New() Me.SetStyle(ControlStyles.SupportsTransparentBackColor,True) Me.BackColor = Color.Transparent ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Dim img As Bitmap = CType(Me.BackgroundImage,Bitmap) 'img.MakeTransparent(img.GetPixel(2,2)) Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None Me.TransparencyKey = img.GetPixel(2,2) End Sub (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |