In this case, the calendar control needs a response to WM_SIZE, so add a protected method called WMSize to the control indexed to the WM_SIZE message, then write the method so that it calculates the proper cell size to allow all cells to be visible in the new size:
type TSampleCalendar = class(TCustomGrid) protected procedure WMSize(var Message: TWMSize); message WM_SIZE; . . . end; . . . procedure TSampleCalendar.WMSize(var Message: TWMSize); var GridLines: Integer; { temporary local variable } begin GridLines := 6 * GridLineWidth; { calculate combined size of all lines } DefaultColWidth := (Message.Width - GridLines) div 7; { set new default cell width } DefaultRowHeight := (Message.Height - GridLines) div 7; { and cell height } end;
//header file class PACKAGE TSampleCalendar : public TCustomGrid { . . . protected: void __fastcall WMSize(TWMSize &Message); BEGIN_MESSAGE_MAP MESSAGE_HANDLER(WM_SIZE, TWMSize, WMSize) END_MESSAGE_MAP(TCustomGrid) };
//implementation file void __fastcall TSampleCalendar::WMSize(TWMSize &Message) { int GridLines; // temporary local variable GridLines = 6 * GridLineWidth; // calculated combined size of all lines DefaultColWidth = (Message.Width - GridLines) / 7; // set new default cell width DefaultRowHeight = (Message.Height - GridLines) / 7; // and cell height }
Now when the calendar is resized, it displays all the cells in the largest size that will fit in the control.
In this case, the calendar control needs to override BoundsChanged so that it calculates the proper cell size to allow all cells to be visible in the new size:
type TSampleCalendar = class(TCustomGrid) protected procedure BoundsChanged; override; . . . end; . . . procedure TSampleCalendar.BoundsChanged; var GridLines: Integer; { temporary local variable } begin GridLines := 6 * GridLineWidth; { calculate combined size of all lines } DefaultColWidth := (Width - GridLines) div 7; { set new default cell width } DefaultRowHeight := (Height - GridLines) div 7; { and cell height } inherited; {now call the inherited method } end;
//header file class PACKAGE TSampleCalendar : public TCustomGrid { . . . protected: void __fastcall BoundsChanged(void); };
//implementation file void __fastcall TSampleCalendar::BoundsChanged(void) { int GridLines; // temporary local variable GridLines = 6 * GridLineWidth; // calculated combined size of all lines DefaultColWidth = (Width - GridLines) / 7; // set new default cell width DefaultRowHeight = (Height - GridLines) / 7; // and cell height TCustomGrid::BoundsChanged(); // now call the inherited method }
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|