gene b.
gene b.

Reputation: 11984

Delphi TDateTimePicker Change Calendar Font

I need to change the font of the TDateTimePicker control to make it larger. The Font property only applies to the edit bar, and I made that one 12px, but need to do the same for the calendar. There's a Calendar control that backs this TDateTimePicker control, how do I get access to it?

I tried looking at other properties and searching for .Calendar or something that would expose the underlying Calendar but haven't had success.

enter image description here

Upvotes: 0

Views: 171

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595961

TDateTimePicker is a thin wrapper around a Win32 DTP control. The VCL does not expose access to the drop-down calendar.

However, you can send the TDateTimePicker a DTM_GETMONTHCAL message (or use the DateTime_GetMonthCal() function):

Gets the handle to a date and time picker's (DTP) child month calendar control.

Do note the following in the documentation:

DTP controls create a child month calendar control when the user clicks the drop-down arrow (DTN_DROPDOWN notification). When the month calendar is no longer needed, it is destroyed (a DTN_CLOSEUP notification is sent on destruction). So your application must not rely on a static handle to the DTP control's child month calendar.

As such, you will have to manipulate the calendar in the TDateTimePicker.OnDropDown event, eg:

uses
  ..., Winapi.CommCtrl;

procedure TForm1.DateTimePicker1DropDown(Sender: TObject);
var
  CalendarWnd: HWND;
begin
  CalendarWnd := DateTime_GetMonthCal(DateTimePicker1.Handle);
  // use CalendarWnd as needed...
end;

UPDATE: as @AmigoJack pointed out in comment, you can instead send the TDateTimePicker a DTM_SETMCFONT message (or use the DateTime_SetMonthCalFont() function):

Sets the font to be used by the date and time picker (DTP) control's child month calendar control.

DateTime_SetMonthCalFont(DateTimePicker1.Handle, DateTimePicker1.Font.Handle, DateTimePicker1.DroppedDown);

Upvotes: 4

Related Questions