469,290 Members | 1,913 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

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

115 100+
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.
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.
Jun 29 '07 #1
12 15609
Wing
28
I recently did this using 3 Numeric Up Down tools then combining them.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim pTime as DateTime
  3. pTime = udHour.Value & ":" & udMin.Value & ":" udSec.Value
  4. pTime = pTime.ToLongTimeString
Hope this helps you out.
Jun 29 '07 #2
remya1000
115 100+
thank for your help. one more dought,
this means 3 numericupdown should be there and seperately we need to select the hours in first numericupdown, minutes in secong numericupdown and so on. and we will combine them.
can we do this in a single one, as we have in date and time properties...
we have hh:mm:ss in one box and if we select the hours, then we can increment only hours and if we select minutes then increment that and so on...

if you have anyidea how to do this plesae help me.
thanks in advance.
Jun 29 '07 #3
Wing
28
Not quite sure about that. I was hoping that the DateTimePicker was going to let me do this but I didn't see anyway to adjust time on the DateTimePicker so I just created my own Time Modifier.
Jun 29 '07 #4
remya1000
115 100+
i just tried using datetimepicker and i can display time, but the formate is like 12:00:00 am to 11:59:59 pm is the whole day.

DateTimePicker1.Format = DateTimePickerFormat.Time
DateTimePicker1.ShowUpDown = True

and i change the property format=time
this will display time.

but i need to display time in format from 00:00:00 to 23:59:59. i dont need to seperate time by using am/pm.

if you have any idea plesae help me.
thanks in advance.
Jun 29 '07 #5
remya1000
115 100+
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
Jun 29 '07 #6
Wing
28
Found it - In the DateTimePicker Properties set Format to Custom and CustomFormat = HH:MM:ss and you will get what I think you need.
Jun 29 '07 #7
Wing
28
Not sure if you need this as well but I just found that DateTimePicker.Value still passes the AM and PM value even though you are using the 24 Hour Format. In order to display your value as 24 Hour format you will need to use the following.

Format(DateTimePicker1.Value, "HH:mm:ss")
Jun 29 '07 #8
remya1000
115 100+
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.
Jul 3 '07 #9
remya1000
115 100+
Expand|Select|Wrap|Line Numbers
  1. Private prevHour As Integer
  2.  
  3. If DateTimePicker1.Value.Hour = 23 Then
  4.             If prevHour = 0 Then
  5.                 DateTimePicker1.Value = DateTimePicker1.Value.AddHours(1)
  6.             End If
  7.         End If
  8.         If DateTimePicker1.Value.Hour = 0 Then
  9.             If prevHour = 23 Then
  10.                 DateTimePicker1.Value = DateTimePicker1.Value.AddHours(-1)
  11.             End If
  12.         End If
  13.         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.
Jul 5 '07 #10
remya1000
115 100+
its working by using this code.....

Expand|Select|Wrap|Line Numbers
  1. Private oldTime As DateTime
  2.  
  3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.         oldTime = DateTimePicker1.Value
  5.     End Sub
  6.  
  7.     Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
  8.         Dim newTime As DateTime = DateTimePicker1.Value
  9.         Dim hr As Integer = newTime.Hour
  10.         Dim min As Integer = newTime.Minute
  11.         Dim sec As Integer = newTime.Second
  12.  
  13.         If (oldTime.Hour = 23 AndAlso newTime.Hour = 0) OrElse (oldTime.Hour = 0 AndAlso newTime.Hour = 23) Then
  14.             hr = oldTime.Hour
  15.         End If
  16.         If (oldTime.Minute = 59 AndAlso newTime.Minute = 0) OrElse (oldTime.Minute = 0 AndAlso newTime.Minute = 59) Then
  17.             min = oldTime.Minute
  18.         End If
  19.         If (oldTime.Second = 59 AndAlso newTime.Second = 0) OrElse (oldTime.Second = 0 AndAlso newTime.Second = 59) Then
  20.             sec = oldTime.Second
  21.         End If
  22.         If hr <> newTime.Hour OrElse min <> newTime.Minute OrElse sec <> newTime.Second Then
  23.             DateTimePicker1.Value = DateTime.Now.Date.Add(New TimeSpan(hr, min, sec))
  24.         End If
  25.         oldTime = DateTimePicker1.Value
  26.  
  27.     End Sub
Jul 5 '07 #11
Hi

what it is mean udHour ? udSec and uDMIN
Dec 30 '15 #12
zmbd
5,400 Expert Mod 4TB
mellouljonathan:
This is a very old thread (9 years) and Mr. Wing has not been active on this site for a very long time.

If you will take a very careful look, you notice that Wing has stated that three Up/Down tools were used, then by inference, in the code these were named "udHour", "udMin" and "udSec" and the value of these controls are being returned to the variable pTime which is then formatted..

If you are having problems with a similar situation, please start a new thread. For context, you can include a link to this thread in your question. You should take a moment to review our FAQ on how to ask a question for some pointers on what to include.
Dec 30 '15 #13

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Targa | last post: by
9 posts views Thread by ME | last post: by
4 posts views Thread by Andrew Poulos | last post: by
4 posts views Thread by flupke | last post: by
6 posts views Thread by Michael Bulatovich | last post: by
6 posts views Thread by Mark Reed | last post: by
3 posts views Thread by Stephen Chaplin | last post: by
2 posts views Thread by jayender.vs | last post: by
7 posts views Thread by WorldIsEnding | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.