Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleChange a form's opacity in VB .NET
Keywordsform, Opacity, transparent, translucent, VB.NET
CategoriesGraphics, VB.NET, Tips and Tricks
 
A form's Opacity property determines how opaque it is. Opacity = 1 means the form is opaque and Opacity = 0 means the form is transparent. Values between 0 and 1 make a translucent form.

Warning: The IDE's Property window displays this value as 0% to 100% but your code must use values between 0 to 1.

This program modifies its form's Opacity in two ways. First, when you adjust the value of the hbarOpacity scroll bar, the program adjusts the form's Opacity.

 
Private Sub hbarOpacity_Scroll(ByVal sender As _
    System.Object, ByVal e As _
    System.Windows.Forms.ScrollEventArgs) Handles _
    hbarOpacity.Scroll
    Me.Opacity = 0.1 + hbarOpacity.Value / 100
    Me.Text = Me.Opacity.ToString
End Sub
 
Second, when you click the Close button, the form enables a timer. The timer gradually reduces the form's Opacity until it dissappears, at which point the timer closes the form. This makes the form fade out gradually.
 
Private Sub btnClose_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnClose.Click
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Timer1.Tick
    Me.Opacity = Me.Opacity - 0.1
    If Me.Opacity <= 0 Then Me.Close()
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated