Domanda

I'm trying to make a clock which would start running from a specific time - e.g. the user sets the time to be 17.35 and it runs from there. What would be the easiest way to do it? I tried setting the time with Timeserial but couldn't figure out how to add time to it so it didn't get me anywhere.

Ideas?

edit: The idea behind the program is to show the user a normal digital clock that has been sped up.

È stato utile?

Soluzione

Add a Label and a Timer component in your form and set the starting date and time (the date won't be visible). So if you set 17:35:00 the time will start from that moment and be updated every second like a clock.

Public Class Form1

    Dim startTime As DateTime

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        startTime = New DateTime(2014, 1, 1, 17, 35, 0) 'setting time at 17:35:00
        Label1.Text = startTime.ToString("HH:mm:ss")

        Timer1.Interval = 1000 '1 tick every second
        Timer1.Start()

    End Sub


    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        startTime = startTime.AddSeconds(1)
        Label1.Text = startTime.ToString("HH:mm:ss")
    End Sub
End Class

Altri suggerimenti

Create a form with a timer on it. Set the timer to 1000ms and enable it. Dim three variables hours, mins, secs. On the timer event, increment the secs. When secs = 60, set secs = 0 and increment the mins; ditto mins to hours, then display the hrs:mins:secs in a format of your choice. Add a button which allows the user to enter starting values for hrs, mins, secs. Depending on what you mean by 'sped up' you could reduce the delay on the timer if you want it to run faster, as opposed to ahead of local time.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top