|
-
May 6th, 2013, 03:44 PM
#1
Thread Starter
Lively Member
[RESOLVED] Countdown Timer on a different form
Hello,
From Form1, I'm trying to Call a sub on Form2 that displays a countdown timer in a label.
First, I tried to it a different way by putting this code in Form1; above the sub "Dim tmrCD As Integer = 120" and code:
Code:
tmrCD = tmrCD - 1
If tmrCD > 0 Then frmTwo.lblCD.Text = ("NEXT ATTEMPT STARTS IN " & tmrCD.ToString)
If frmTwo.lblCD.Text = "0" Then
frmTwo.Timer1.Stop()
End If
But it only displayed 119 and didn't count down. It was obvious to me that the reason is because the Timer is not being used.
Then I tried putting this into Form2
Code:
Private CD As Integer = 120
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Me.lblCD.Text = ("NEXT ATTEMPT STARTS IN " & CD.ToString("00"))
If CD = 0 Then
Me.Timer1.Enabled = False
Else
CD -= 1
End If
End Sub
But it started counting down the instant the page loaded, which is completely opposite from what I need! I need Form1 to finish it's job when a button is pressed, THEN call Timer1_Tick at the bottom of the sub on Form1 when it's finished with it's job. In form1, I tried using:
But got the error:
Property access must assign to the property or use it's value.
I'm not sure how to proceed. Ideas?
-
May 6th, 2013, 06:11 PM
#2
Re: Countdown Timer on a different form
Add public sub in frmTwo and call it from form1, frmTwo.StartCountDownTimer
Code:
' add this to frmTwo
Public Sub StartCountDownTimer()
Timer1.Interval = 1000
Timer1.Start
End Sub
-
May 6th, 2013, 08:47 PM
#3
Thread Starter
Lively Member
Re: Countdown Timer on a different form
-
May 7th, 2013, 06:12 AM
#4
Re: [RESOLVED] Countdown Timer on a different form
BTW: you can start the timer like this frmTwo.Timer1.Start(), but i suggest using public sub because it is more handy specially if you want to perform some tasks before or after starting the timer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|