Date Time Picker

  • Thread starter Thread starter Chris Oswald
  • Start date Start date
C

Chris Oswald

Is it possible to change the initial focus on the DateTimePicker
control. For instance, if I have month, day, and year, can I default
the focus to the year. I don't see any methods that allow me to to do
this. I'm betting I will have to do a custom control, but hopefully
not. I'm running NETCF 2.0.
 
The only solution I can see at the moment is to trap the GetFocus event
and send right-arrow keystroke twice to move the cursor to the year
field...

Chris Oswald napsal:
 
That's a good idea! Thanks for thinking outside the box. I still have
a few issues to figure out if there are multiple DTPs on a form.

If there are, I only want to reselect if they tab to the DTP or if it's
the first item to get focus. Otherwise, if the user selects the month
day or year i don't want to override what they have selected.
 
I don't fully understand what you exacly need, but I thing this
GetFocus-method can do anything you want - you just have to specify the
condition for programatic cursor repositioning when DTP gets focused...

DTP1.Getfocus += new EventHandler(MyDTPHandler);
....
DTP99.Getfocus += new EventHandler(MyDTPHandler);
....
private void MyDTPHandler(object sender, EventArgs e)
{
if (sender == DTP123 || some_other_condition)
{
IntPtr hwnd = (sender as Control).Handle;
Win32Window.SendMessage(hwnd, (int)WM.KEYDOWN, (int)Keys.Right,
0);
Win32Window.SendMessage(hwnd, (int)WM.KEYUP, (int)Keys.Right, 0);
Win32Window.SendMessage(hwnd, (int)WM.KEYDOWN, (int)Keys.Right,
0);
Win32Window.SendMessage(hwnd, (int)WM.KEYUP, (int)Keys.Right, 0);

}
}

Chris Oswald napsal:
 
Back
Top