select time (hours,minutes,second) in updown arrow

remya1000

Well-known member
Joined
Mar 29, 2007
Messages
122
Programming Experience
Beginner
how can i select time (hours,minutes,second) in updown arrow buttons in VB.NET.

as we have current time displayed in date and time properties in our system.

in date and time properties, while we press updown arrown, that will change only hour first, and if we select the minutes and press updown arrow, minutes will get changed and if we select the seconds and press updown arrow, it will change the seconds.
if we use numericupdown tool, i can give only hour, or minutes, or second. i cant combine all the three hours:minutes:second in that numericupdown arrow.
if i use domainupdown tool, i dont know how to select hours,minutes seperately inside a single updown.
i'm attaching a picture just shows what i mean.
if you have any idea how to do this please help me. and if you can give an example that will be a great help for me.
thanks in advance.
 

Attachments

  • SelectTime.bmp
    21.4 KB · Views: 29
can i able to set time as in that attachement.
if you have any idea about this please help me.
thanks in advance.
 
heay i can make it display by using datetimepicker.
i got this help from internet.

i placed a datetimepicker, and in properties, i changed
showupdown = true
format = custom
custom format = HH:mm:ss
and while running the program, i can set the time.

can we set like this.....
so now hours values will be from 00 to 23. so when it reach 23, if we press up arrow the value should not more. then only, if we press down arrow only the value should change. can we set like that.
if you have anyidea how to do that please help me.
thank in advance and thanks for the help.
can we do in this way in datetimepicker
 
whether i can set the datetimepicker as this.
now if we press up arrow, the value will increment from 0 to 23 and when it reach 23, it again starts from 0 and go on....
i need to set it as, if i press up arrow i need to increment the value from 0 to 23. and when it reach 23 it should stop. it should not rotate again from 0 to 23. once it reach 23, if we need to select something else we need to press down arrow. and if i press down arrow it should decrement the values. and once it reach 0 it should not start again from 23 to 0.
whether i can set the values like this in datetimepicker.
if you have any idea please let me know.
thanks in advance.
 
Private prevHour As Integer

If DateTimePicker1.Value.Hour = 23 Then
If prevHour = 0 Then
DateTimePicker1.Value = DateTimePicker1.Value.AddHours(1)
End If
End If
If DateTimePicker1.Value.Hour = 0 Then
If prevHour = 23 Then
DateTimePicker1.Value = DateTimePicker1.Value.AddHours(-1)
End If
End If
prevHour = DateTimePicker1.Value.Hour

when i give this code, when the hours value reach 23 and if we press uparrow, it wont rotate from 0-23 as i need. and when hour value reach 0 and if we press down arrow, it wont rotate from 23-0 as i need.
likewise i need to set it for minutes and for seconds.
i need to set it as, if i press up arrow i need to increment the minutes value from 0-59. and when it reach 59 it should stop. it should not rotate again from 0 to 59. once it reach 59, if we need to select something else we need to press down arrow. and if i press down arrow it should decrement the values. and once it reach 0 it should not start again from 59 to 0. like wise as we set for hour (the values should not rotate), sameway i need to set for minutes and for seconds.
whether i can set the values like this in datetime picker.
if you have any idea please let me know.
thanks in advance.
 
its working by using this code....

VB.NET:
Private oldTime As DateTime

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        oldTime = DateTimePicker1.Value
    End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        Dim newTime As DateTime = DateTimePicker1.Value
        Dim hr As Integer = newTime.Hour
        Dim min As Integer = newTime.Minute
        Dim sec As Integer = newTime.Second

        If (oldTime.Hour = 23 AndAlso newTime.Hour = 0) OrElse (oldTime.Hour = 0 AndAlso newTime.Hour = 23) Then
            hr = oldTime.Hour
        End If
        If (oldTime.Minute = 59 AndAlso newTime.Minute = 0) OrElse (oldTime.Minute = 0 AndAlso newTime.Minute = 59) Then
            min = oldTime.Minute
        End If
        If (oldTime.Second = 59 AndAlso newTime.Second = 0) OrElse (oldTime.Second = 0 AndAlso newTime.Second = 59) Then
            sec = oldTime.Second
        End If
        If hr <> newTime.Hour OrElse min <> newTime.Minute OrElse sec <> newTime.Second Then
            DateTimePicker1.Value = DateTime.Now.Date.Add(New TimeSpan(hr, min, sec))
        End If
        oldTime = DateTimePicker1.Value
        
    End Sub
 
Back
Top