[BeginnerTut] Making a timer countdown

Discussion in 'Programming General' started by GordonBM, Apr 4, 2008.

[BeginnerTut] Making a timer countdown
  1. Unread #1 - Apr 4, 2008 at 2:37 PM
  2. GordonBM
    Referrals:
    0

    GordonBM Guest

    [BeginnerTut] Making a timer countdown

    Very simple.

    Make a textbox, a button and two timers.
    Set Timer1 interval to 60000 (or whatever you like, I use 60000 for this example) and set Timer2 interval to 1.
    Now double click the button to open the code and fill this in:

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Timer2.Enabled = True
            Timer1.Enabled = True
        End Sub
    Now go back to the design tab, double click the Timer2 and fill this in the code section:

    Code:
        Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
            If Timer2.Enabled = True Then
                Timer1.Interval = Timer1.Interval - 1
                TextBox1.Text = Timer1.Interval
            End If
        End Sub
    This means everytime Timer1 counts 1 down, Timer2 will be activated making the text of textbox1 update.

    Full code:
    Public Class Form1

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Timer2.Enabled = True
            Timer1.Enabled = True
        End Sub
    
        Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
            If Timer2.Enabled = True Then
                Timer1.Interval = Timer1.Interval - 1
                TextBox1.Text = Timer1.Interval
            End If
        End Sub
    End Class
    This was a VERY beginner tutorial.
    Cheers.
     
< My First C++ Program :) | echo in C >

Users viewing this thread
1 guest


 
 
Adblock breaks this site