473,883 Members | 1,796 Online

# Opacity on form

I want a windows form to act like the one in Outlook when you get a new
message
and it is visible for about a couple of seconds and then the opacity
decreases and the form dissapears in the end
I have tried with
Dim p As Integer
Dim Vent As Integer
For p = 100 To 0 Step -1
Me.Opacity = p
For Vent = 1 To 100000
Next Vent
Next p
but the form is flickering and the opacity factor doesn't change.

reidarT
Jul 4 '06 #1
2 2350
try this code in VB, it wud solve ur problem
firstly declare a public variable p
e.g.

Public p As Integer = 100 ''here i predifine the initial opacity to
100%

Then in the form load event of the form, change the opacity to ANY
VALUE OTHER THAN 1(100% Opacity)..the best is 99.9% (i.e 0.999)
e.g.

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
Me.Opacity = 0.999 ''this means opacity is set to 99.9%
End Sub

Then drop in a Timer control into tht form and write the following code
in the "elapsed" property of the timer :

Private Sub Timer1_Elapsed( ByVal sender As System.Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles Timer1.Elapsed
p = p - 1 'here i gradually decrease the opacity on evry
interval of the timer
Me.Opacity = (p / 100) 'convert my value to percentage by
dividing by 100
If Me.Opacity = 0.01 Then ''if opacity reaches 1% then close
the form
Me.Close()
End If
End Sub

Finally in the "interval" property of the timer, set ur own values
according to how fast or how slow u want the form to disappear.i used
1000 (i.e. 1000 millisecs = 1 second), so the opacity is decreased by
1% every one second,so..the form becomes invisible and finally closes
in 100 seconds.YOU CAN CHANGE THIS VALUE ACCORDING TO YOUR CONVINIENCE
AS HOW FAST/SLOW U NEED YOUR FORM TO CLOSE.
u can use 500 as interval..this will close your form in 50
seconds..value 100 will close your form in 10 seconds..and so
on.........

if u want to start the vanishing upon clicking a botton/event..then at
first disable the timer and enable it on that event being fired.
ok..gud luckk
Raj

reidarT wrote:
I want a windows form to act like the one in Outlook when you get a new
message
and it is visible for about a couple of seconds and then the opacity
decreases and the form dissapears in the end
I have tried with
Dim p As Integer
Dim Vent As Integer
For p = 100 To 0 Step -1
Me.Opacity = p
For Vent = 1 To 100000
Next Vent
Next p
but the form is flickering and the opacity factor doesn't change.

reidarT
Jul 4 '06 #2
It's as easy as this:
For p as integer = 100 to 0 step -1
Opacity = CDbl(p)/100
refresh
Threading.Threa d.Sleep 100 'wait for 0,1 second
Next
reidarT wrote:
I want a windows form to act like the one in Outlook when you get a new
message
and it is visible for about a couple of seconds and then the opacity
decreases and the form dissapears in the end
I have tried with
Dim p As Integer
Dim Vent As Integer
For p = 100 To 0 Step -1
Me.Opacity = p
For Vent = 1 To 100000
Next Vent
Next p
but the form is flickering and the opacity factor doesn't change.

reidarT

Jul 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.