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

时间:2020-03-05 18:45:35  来源:igfitidea点击:

我正在编写一个简单的应用程序,它将在屏幕的一个角上有一个很小的窗体,可以自我更新。

我非常希望该表单具有透明性,并且可以让用户配置透明性。

有没有简单的方法可以做到这一点?

解决方案

回答

我们可以设置Form.Opacity属性。它应该做我们想要的。

回答

我们可以尝试使用Form的Opacity属性。这是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通道的颜色。然后,我们可以根据需要绘制表单,背景将是透明的,其他内容将完全可见。此外,我们可以将背景设置为低不透明度图层,以便可以半透明地浏览表单。