DateTimePicker Parts

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Is there a way, via code, to modify which portion of the
DateTimePicker control is selected when the control gets
focus? For example, if the control contains 12/25/2003,
could the portion that is selected be the Day (25) portion
of the control?
 
Hello Dave,

Thanks for your post. Based on my experience and research, DateTimePicker
does not provide any property/method to set/get the selected portion of
Date text. To work around this problem, I suggest that you can handle the
ValueChanged event and ensure that a user can only change the Day portion
of the control.

DateTimePicker.ValueChanged Event
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwindowsformsdatetimepickerclassvaluechangedtopic.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Dave,

Thanks for your feedback. When your DatePicker control is got focused, you
may try generating a mouse click message at the left of the control in
order to put the cursor there.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Dave,

You can use P/Invoke to call unmanaged API SendInput() which synthesizes
mouse clicks. Please tell me what programming language you are using so
that I will try to write some sample code snippet.

SendInput
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI
/WindowsUserInterface/UserInput/KeyboardInput/KeyboardInputReference/Keyboar
dInputFunctions/SendInput.asp?frame=true

I look forward to your reply.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Using VB.NET. Really appreciate your help!
-----Original Message-----
Hi Dave,

You can use P/Invoke to call unmanaged API SendInput() which synthesizes
mouse clicks. Please tell me what programming language you are using so
that I will try to write some sample code snippet.

SendInput
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/winui/WinUI
utReference/Keyboar
dInputFunctions/SendInput.asp?frame=true

I look forward to your reply.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

.
 
Hello Dave,

Thanks for your response. The following sample suppose that you the
DateTimePicker is of "Short" format(12/25/2003 ) and it post mouse click
messages to the begining of the control (x=6, y=6) so that the month (12)
will be selected whenever it got focus.

'-------------------------------code snippet----------------------------
Declare Auto Function PostMessage Lib "user32" Alias "PostMessageA"
(ByVal hwnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal
lParam As Int32) As Int32
Public Const MK_LBUTTON = &H1
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202


Private Sub DateTimePicker1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DateTimePicker1.GotFocus
Dim lParam As Int32
lParam = 393222 ' equals to C code "MAKELPARAM(6,6)"
PostMessage(DateTimePicker1.Handle(), WM_LBUTTONDOWN, MK_LBUTTON,
lParam)
PostMessage(DateTimePicker1.Handle(), WM_LBUTTONUP, 0, lParam)
End Sub
'--------------------------------end of-------------------------------------

Please check it on your side.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top