A counter variable that increases and decreases.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I got this problem when I was coding a splash screen of a certain application. I wanted to add fade in and fade out effects to the splash screen while it is loading and unloading. So I used the opacity property of the form control and Timer1 is a timer control
whose interval property is set to 10 milliseconds. Below is the code I used. I’m new to programming and what I want to know is, is there a better way to do this.
<span style="font-size:10.0pt; font-family:Courier New; color:blue Public<span style="font-size:10.0pt; font-family:Courier New
<span style="color:blue Class frmSplash
<span style="font-size:10.0pt; font-family:Courier New; color:blue Dim<span style="font-size:10.0pt; font-family:Courier New Counter
<span style="color:blue As <span style="color:blue Integer
<span style="font-size:10.0pt; font-family:Courier New; color:blue Private<span style="font-size:10.0pt; font-family:Courier New
<span style="color:blue Sub Timer1_Tick(<span style="color:blue ByVal sender
<span style="color:blue As System.Object, <span style="color:blue ByVal e
<span style="color:blue As System.EventArgs) <span style="color:blue Handles Timer1.Tick
<span style="font-size:10.0pt; font-family:Courier New <span style="font-family:Courier New; font-size:10pt Counter += 10
<span style="font-family:Courier New; font-size:10pt <span style="white-space:pre If<span style="font-family:Courier New; font-size:10pt Counter <= 100
<span style="font-family:Courier New; font-size:10pt; color:blue Then
<span style="font-family:Courier New; font-size:10pt; color:blue <span style="white-space:pre Me<span style="font-family:Courier New; font-size:10pt .Opacity = Counter / 100
<span style="font-size:10.0pt; font-family:Courier New
<span style="color:blue ElseIf Counter >= 800 <span style="color:blue
Then
<span style="font-size:10.0pt; font-family:Courier New
<span style="color:blue Me.Opacity = (900 - Counter) / 100
<span style="font-size:10.0pt; font-family:Courier New
<span style="color:blue End <span style="color:blue If
<span style="font-size:10.0pt; font-family:Courier New <span style="font-family:Courier New; font-size:10pt; color:blue If<span style="font-family:Courier New; font-size:10pt Counter = 900
<span style="font-family:Courier New; font-size:10pt; color:blue Then
<span style="font-size:10.0pt; font-family:Courier New Timer1.Enabled =
<span style="color:blue False
<span style="font-size:10.0pt; font-family:Courier New
<span style="color:green Create a new instance of the child form.
<span style="font-size:10.0pt; font-family:Courier New
<span style="color:blue Dim ChildForm <span style="color:blue As <span style="color:blue
New MDIParent1
<span style="font-size:10.0pt; font-family:Courier New
<span style="color:green Make it a child of this MDI form before showing it.
<span style="font-size:10.0pt; font-family:Courier New MDIParent1.Show()
<span style="font-size:10.0pt; font-family:Courier New
<span style="color:blue Me.Close
<span style="font-size:10.0pt; font-family:Courier New <span style="color:blue End
<span style="color:blue If
<span style="font-size:10.0pt; font-family:Courier New; color:blue End<span style="font-size:10.0pt; font-family:Courier New
<span style="color:blue Sub

<span style="font-size:10.0pt; font-family:Courier New; color:blue End<span style="font-size:10.0pt; font-family:Courier New
<span style="color:blue Class
<br/>

View the full article
 
Back
Top