reproductor





lunes, 6 de febrero de 2012

Timer en cuenta regresiva


Public Class Form1
    Dim restante As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        restante = 240
        Timer1.Interval = 1000

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If restante >= 0 Then

            Label1.Text = restante

            restante = restante - 1

        Else

            Timer1.Enabled = False

            MsgBox("Finalizó el tiempo")

        End If

    End Sub
    Public Sub TimerOn()

        If restante > 0 Then

            Timer1.Enabled = True

        Else

            Timer1.Enabled = False

        End If
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TimerOn()

    End Sub
End Class

3 comentarios:

  1. prueba con este

    Public Class Form1
    Dim negativo As Integer = 30


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    negativo -= 1
    Label1.Text = negativo
    If negativo = 0 Then
    Label1.Text = "Hola"
    negativo = 30
    Timer1.Stop()
    End If
    End Sub
    End Class

    ResponderEliminar
  2. prueba con este

    Public Class Form1
    Dim negativo As Integer = 30


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    negativo -= 1
    Label1.Text = negativo
    If negativo = 0 Then
    Label1.Text = "Hola"
    negativo = 30
    Timer1.Stop()
    End If
    End Sub
    End Class

    ResponderEliminar