Tuesday, August 18, 2009The VCL component TMonthCalendar that is a wrapper for the Microsoft COMCTRL MonthCalendar has a WeekNumbers property with which you can control whether week numbers are displayed or not in the calendar. It also has properties ShowToday and ShowTodayCircle to control whether to display today's date in the calendar. The VCL TDateTimePicker is also a wrapper for a Microsoft COMCTRL DateTimePicker that at first sight has an identical calendar as the MonthCalendar as dropdown control. Yet, there is nowhere a property to control displaying weeknumbers and/or today's date in this calendar. With a few lines of code though, it is possible to have control over this. Implement the TDateTimePicker.OnDropDown event and add the code:
procedure TForm1.DateTimePicker1DropDown(Sender: TObject); var dwstyle: dword; mch: THandle; rct: TRect; begin mch := SendMessage((Sender as TDateTimePicker).Handle, DTM_GETMONTHCAL, 0,0); dwStyle := GetWindowLong(mch, GWL_STYLE); // add this line if you want to see week numbers in the dropdown calendar dwStyle := dwStyle or MCS_WEEKNUMBERS; // add this line if you do not want to see the circle before today's date in the dropdown calendar dwStyle := dwStyle or MCS_NOTODAYCIRCLE; // add this line if you do not want to see today's date in the dropdown calendar dwStyle := dwStyle or MCS_NOTODAY; SetWindowLong(mch, GWL_STYLE, dwStyle); // adapt the size of the dropdown calendar as the default size is a bit too small SendMessage(mch, MCM_GETMINREQRECT, 0, integer(@rct)); MoveWindow(mch, 0, 0, rct.Right + 2, rct.Bottom + 2, True); end;
This blog post has not received any comments yet.
Previous | Next | Index