有没有一种简单的方法可以在 VB .NET 应用程序中创建透明表单?

StackOverflow https://stackoverflow.com/questions/36563

  •  09-06-2019
  •  | 
  •  

我正在编写一个简单的应用程序,它将在屏幕的一个角落放置一个小表单,并进行自我更新。

我真的很希望该表单是透明的并且透明度可以由用户配置。

有什么简单的方法可以实现这一目标吗?

有帮助吗?

解决方案

您可以尝试使用 不透明度 表格的属性。以下是 MSDN 页面上的相关片段:

private Sub CreateMyOpaqueForm()
   ' Create a new form.
   Dim form2 As New Form()
   ' Set the text displayed in the caption.
   form2.Text = "My Form"
   ' Set the opacity to 75%.
   form2.Opacity = 0.75
   ' Size the form to be 300 pixels in height and width.
   form2.Size = New Size(300, 300)
   ' Display the form in the center of the screen.
   form2.StartPosition = FormStartPosition.CenterScreen

   ' Display the form as a modal dialog box.
   form2.ShowDialog()
End Sub

其他提示

Form.Opacity = 0.0 页面加载时

大约一年前,我在一个应用程序上设置了类似您正在谈论的内容。用一个 While 循环有一个小 Sleep 你可以设置一个很好的淡入淡出效果。

我不太清楚你所说的透明是什么意思,但是如果你使用WPF,你可以设置 AllowTransparency = True 在您的表单上,然后删除表单的样式/边框,然后将背景设置为具有零 Alpha 通道的颜色。然后,您可以在表单上绘制您想要的所有内容,背景将是透明的,其他内容将完全可见。此外,您可以将背景设置为低不透明度图层,这样您就可以看到一半的表单。

您可以设置 Form.Opacity 财产。它应该做你想做的事。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top