How to create Animation (Fade in & Fade out) in Visual Basic.Net


How to create Animation (Fade in & Fade out) in Visual Basic.Net. We will be using three timers for this animation. We will be actually changing the opacity of the form for this animation. We are actually using conditional statements to check the opacity of the form for this animation in VB.Net.

How to create Animation (Fade in & Fade out) in Visual Basic.Net. We will be using three timers for this animation. We will be actually changing the opacity of the form for this animation.
First of all create a new form in your VB.Net project and add Two buttons and Three Timers on the form.
Change the interval of the three Timers to 1000.Also change the name of the buttons to btnfade and btnunfade.
Type the following code on the click event of the btnfade.



Private Sub btnfade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfade.Click
Timer1.Start()
Timer2.Start()
Timer3.Stop()
End Sub

Type the following code on the click event of the btnunfade.

Private Sub btnunfade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnunfade.Click
Timer1.Stop()
Timer2.Stop()
Timer3.Start()
End Sub

And finally type the following code on the events of the three timers.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Me.Opacity <= 1.0 Then
Me.Opacity = Me.Opacity - 0.1

End If
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Me.Opacity <= 0.2 Then
End
End If
End Sub

Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
If Me.Opacity = Me.Opacity < 1.0 Then
Me.Opacity = Me.Opacity + 0.1
End If
End Sub

Now, run the project and see the result which will be like the image shown here.

Regards


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: