Search code examples
c#winformsdatetimepicker

Accurate running time in Windows form


I have DateTimePicker on my form and I want it to only display TIME I use the code below to do that and it worked

dtpTimeIn.Format = DateTimePickerFormat.Time;
dtpTimeIn.Value = DateTime.Now;
dtpTimeIn.ShowUpDown = true;

Now my problem is, I want it to be a running time wherein the seconds is continuously running I used DateTime.Now but it's not working

Please help me to find another solution


Solution

  • This works for me. Here's my VB example. The seconds/time updates every timer1.tick.

    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            dtpTimeIn.Format = DateTimePickerFormat.Time
            dtpTimeIn.Value = DateTime.Now
            dtpTimeIn.ShowUpDown = True
    
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    
            dtpTimeIn.Value = DateTime.Now
    
        End Sub
    End Class