1. Home
  2. Computing & Technology
  3. Delphi Programming

How to show week numbers in a TDateTimePicker

By , About.com Guide

If you want your TDateTimeCaledar to display week numbers when the Calendar is dropped down, set this code for the OnDropDown event:

~~~~~~~~~~~~~~~~~~~~~~~~~
uses
   CommCtrl;

//interface

type
   THackCommonCalendar = class(TCommonCalendar) ;

//implementation

procedure TForm1.DateTimePicker1DropDown(Sender: TObject) ;
var
   Style: Integer;
   ReqRect: TRect;
   MaxTodayWidth: Integer;
begin
   with THackCommonCalendar(Sender as TDateTimePicker) do
   begin
     Style := GetWindowLong(CalendarHandle, GWL_STYLE) ;
     SetWindowLong(CalendarHandle, GWL_STYLE, Style or MCS_WEEKNUMBERS) ;
     FillChar(ReqRect, SizeOf(TRect), 0) ;
     Win32Check(MonthCal_GetMinReqRect(CalendarHandle, ReqRect)) ;
     MaxTodayWidth := MonthCal_GetMaxTodayWidth(CalendarHandle) ;
     if MaxTodayWidth > ReqRect.Right then ReqRect.Right := MaxTodayWidth;
     SetWindowPos(CalendarHandle, 0, 0, 0, ReqRect.Right, ReqRect.Bottom, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOZORDER) ;
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to enable file download from an asp.net page
« From TTime and TDate to TDateTime

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2004 Delphi Tips
  7. How to show week numbers in a TDateTimePicker

©2009 About.com, a part of The New York Times Company.

All rights reserved.