There's no direct way of doing this, but if you include the following code, you can manipulate the location of the focus in a TDateTimePicker control:
{$IF CompilerVersion >= 17 }
{$DEFINE D2005UP }
{$ELSE }
{$UNDEF D2005UP }
{$ENDIF }
{$IF CompilerVersion >= 20 }
{$DEFINE D2009UP }
{$ELSE }
{$UNDEF D2009UP }
{$ENDIF }
PROCEDURE SendKeys(CONST Keys : ARRAY OF WORD);
VAR
{$IFDEF D2009UP }
InputEvents : TArray<TInput>;
{$ELSE }
InputEvents : ARRAY OF TInput;
{$ENDIF }
{$IFNDEF D2005UP }
I : INTEGER;
{$ENDIF }
Key : WORD;
PROCEDURE Add(Key : WORD ; Action : WORD = 0);
VAR
INP : TInput;
BEGIN
FillChar(INP,SizeOf(TInput),0);
INP.Itype:=INPUT_KEYBOARD;
INP.ki.wVk:=Key;
INP.ki.wScan:=0;
INP.ki.dwFlags:=Action;
INP.ki.time:=0;
INP.ki.dwExtraInfo:=0;
{$IFDEF D2009UP }
InputEvents:=InputEvents+[INP]
{$ELSE }
SetLength(InputEvents,SUCC(LENGTH(InputEvents)));
InputEvents[HIGH(InputEvents)]:=INP
{$ENDIF }
END;
PROCEDURE AddKeyDown(Key : WORD);
BEGIN
Add(Key)
END;
PROCEDURE AddKeyUp(Key : WORD);
BEGIN
Add(Key,KEYEVENTF_KEYUP)
END;
PROCEDURE AddKeyPress(Key : WORD);
BEGIN
AddKeyDown(Key);
AddKeyUp(Key)
END;
BEGIN
IF LENGTH(Keys)=0 THEN EXIT;
{$IFDEF D2005UP }
FOR Key IN Keys DO AddKeyPress(Key);
{$ELSE }
FOR I:=LOW(Keys) TO HIGH(Keys) DO BEGIN
Key:=Keys[I];
AddKeyPress(Key)
END;
{$ENDIF }
SendInput(LENGTH(InputEvents),InputEvents[LOW(InputEvents)],SizeOf(TInput));
Application.ProcessMessages
end;
PROCEDURE SetDateTimePickerFocus(DTP : TDateTimePicker ; FocusTo : CHAR);
VAR
S : STRING;
BEGIN
DTP.SetFocus;
Application.ProcessMessages;
S:=DTP.Format; DTP.Format:='HH';
Application.ProcessMessages;
DTP.Format:=S;
Application.ProcessMessages;
CASE UpCase(FocusTo) OF
'H' : ; // NOTHING //
'M' : SendKeys([VK_RIGHT]);
'S' : SendKeys([VK_RIGHT,VK_RIGHT])
ELSE // OTHERWISE //
RAISE ERangeError.Create('Unsupported FocusTo value in SetDateTimePickerFocus: "'+FocusTo+'"')
END
END;
{$IFDEF D2005UP }
TYPE
TDateTimePickerHelper = CLASS HELPER FOR TDateTimePicker
PROCEDURE SetFocusTo(C : CHAR);
END;
{ TDateTimePickerHelper }
PROCEDURE TDateTimePickerHelper.SetFocusTo(C : CHAR);
BEGIN
SetDateTimePickerFocus(Self,C)
END;
{$ENDIF }
If you use Delphi 2005 and up, there's also a class helper for the TDateTimePicker control.
Usage (before Delphi 2005):
SetDateTimePickerFocus(DateTimePicker1,'S'); // 'H', 'M' or 'S' to select field
Usage (Delphi 2005+):
DateTimePicker1.SetFocusTo('S'); // 'H', 'M' or 'S' to select field