|
-
Aug 14th, 2007, 10:30 AM
#1
Thread Starter
Hyperactive Member
[2005] DateTimePicker Up/Down Arrow Problem
Hello,
I have a datetimepicker on my form which is formatted to show time (HH:mm)
This works a treat, but what I'd really like to do is have the minutes increment in blocks of 15 instead of the usual 1.
Is this possible ?
If so, how ?
Thanks.
-
Aug 15th, 2007, 02:02 AM
#2
Re: [2005] DateTimePicker Up/Down Arrow Problem
There's no way to do that with a regular DTP. You'd have to inherit the control and then implement the functionality yourself, although I'm not 100% sure how. You could override the WndProc method and work with its Windows messages perhaps. You may also be able to access the internal spinner control via its Controls collection. That may enable you to handle its events and determine when the value is to be incremented or decremented. This is all just conjecture though.
-
Aug 15th, 2007, 07:18 PM
#3
Re: [2005] DateTimePicker Up/Down Arrow Problem
If you disallow the user from entering a time manually (this action is inhibited in the in code below), this gets you most of the way there...
Code:
Option Strict On
Option Strict On
Public Class Form1
Dim ReferenceClock As Date
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
'Set DateTimePicker Format Hour:Minutes (24 hour with no Seconds field)
DT.Format = DateTimePickerFormat.Custom
DT.CustomFormat = "HH:mm"
DT.ShowUpDown = False
'Initialize the DateTimePicker to today
Date.TryParse(Date.Today.ToString("dd/MM/yyyy") & " 00:00:00", ReferenceClock)
DT.Value = ReferenceClock
End Sub
Private Sub DT_KeyDown( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles DT.KeyDown
'Note: We cannot discern between an hour or minute adjustment
'so the up/down keys will have the same function whether in the
'hour or minute field
If e.KeyValue = Keys.Up Or e.KeyValue = Keys.Down Then
'Increment
If e.KeyValue = Keys.Up Then ReferenceClock = ReferenceClock.AddMinutes(15)
'Decrement
If e.KeyValue = Keys.Down Then ReferenceClock = ReferenceClock.AddMinutes(-15)
'Update DateTimePicker
DT.Value = ReferenceClock
End If
End Sub
Private Sub DT_ValueChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DT.ValueChanged
'Since the DateTimePicker will default to an increment/decrement of 1
'this updates it again when the KeyDown event is completed
'This also inhibits the user from manually specifying a time
DT.Value = ReferenceClock
End Sub
End Class
Last edited by Bulldog; Aug 15th, 2007 at 08:30 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|