Is there an easy way to do transparent forms in a VB .NET app?
-
09-06-2019 - |
Question
I'm writing a simple app that's going to have a tiny form sitting in one corner of the screen, updating itself.
I'd really love for that form to be transparent and to have the transparency be user-configurable.
Is there any easy way to achieve this?
Solution
You could try using the Opacity property of the Form. Here's the relevant snippet from the MSDN page:
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
OTHER TIPS
Set Form.Opacity = 0.0
on page load
I set something like what your talking about on an app about a year ago. Using a While
loop with a small Sleep
you can setup a nice fading effect.
I don't know exactly what you mean by transparent, but if you use WPF you can set AllowTransparency = True
on your form and then remove the form's style/border and then set the background to a color that has a zero alpha channel. Then, you can draw on the form all you want and the background will be see-through and the other stuff will be fully visible. Additionally, you could set the background to a low-opacity layer so you can half see through the form.
You can set the Form.Opacity
property. It should do what you want.