home *** CD-ROM | disk | FTP | other *** search
- unit calend;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ComCtrls, ToolWin, Grids, Calendar, StdCtrls, ExtCtrls, Buttons, Menus;
-
- type
- TForm1 = class(TForm)
- Calendar1: TCalendar;
- Panel1: TPanel;
- RichEdit1: TRichEdit;
- CoolBar1: TCoolBar;
- DateTimePicker1: TDateTimePicker;
- Panel2: TPanel;
- ShowHideCalendarBtn: TButton;
- PopupMenu1: TPopupMenu;
- UseShortDateFormatMenuItem: TMenuItem;
- UseLongDateFormatMenuItem: TMenuItem;
- UseDaywithDateMenuItem: TMenuItem;
- PopupMenu2: TPopupMenu;
- ToggleDateFormat1: TMenuItem;
- ConfigureDateTimePicker1: TMenuItem;
- procedure DateTimePicker1Change(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Calendar1Change(Sender: TObject);
- procedure RichEdit1KeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure ShowHideCalendarBtnClick(Sender: TObject);
- procedure FormResize(Sender: TObject);
- procedure UseShortDateFormatMenuItemClick(Sender: TObject);
- procedure UseLongDateFormatMenuItemClick(Sender: TObject);
- procedure UseDaywithDateMenuItemClick(Sender: TObject);
- procedure DateTimePicker1DblClick(Sender: TObject);
- procedure ToggleDateFormat1Click(Sender: TObject);
- procedure ConfigureDateTimePicker1Click(Sender: TObject);
- private
- { Private declarations }
- procedure WMGetMinMaxInfo(var MSG: Tmessage); message WM_GetMinMaxInfo;
- procedure ToggleDateTimePickerFormat;
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
- const
- MINFORMHEIGHT = 300;
- MINFORMWIDTH = 450;
- DAYWITHDATEFMT = 'dddd, mmmm d, yyyy';
- DATEFMT : String = DAYWITHDATEFMT;
- implementation
-
- uses configform;
-
- {$R *.DFM}
-
- procedure TForm1.DateTimePicker1Change(Sender: TObject);
- var
- Year, Month, Day : Word;
- begin
- DecodeDate(DateTimePicker1.Date, Year, Month, Day);
- Calendar1.Year := Year;
- Calendar1.Month := Month;
- Calendar1.Day := Day;
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Panel1.Height := Form1.ClientHeight Div 2;
- DateTimePicker1.Align := alTop;
- Panel1.Align := alBottom;
- Calendar1.Align := alClient;
- end;
-
- procedure TForm1.Calendar1Change(Sender: TObject);
- var
- Year, Month, Day : Word;
- begin
- DecodeDate(DateTimePicker1.Date, Year, Month, Day);
- DateTimePicker1.Date := EncodeDate(Year, Month, Calendar1.Day);
- end;
-
- procedure TForm1.RichEdit1KeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- if Key = vk_F8 then
- RichEdit1.selText := FormatDateTime(DATEFMT, DateTimePicker1.Date );
- end;
-
- procedure TForm1.ShowHideCalendarBtnClick(Sender: TObject);
- begin
- if Calendar1.Visible then
- begin
- Calendar1.Hide;
- Calendar1.Align := alNone;
- Panel1.Align := alClient;
- ShowHideCalendarBtn.Caption := 'Show Calendar';
- end
- else
- begin
- Panel1.Align := alNone;
- Panel1.Align := alBottom;
- Panel1.Height := Form1.ClientHeight Div 2;
- Calendar1.Align := alClient;
- Calendar1.Show;
- ShowHideCalendarBtn.Caption := 'Hide Calendar';
- end;
- end;
-
- procedure TForm1.FormResize(Sender: TObject);
- begin
- Panel1.Height := Form1.ClientHeight Div 2;
- end;
-
- procedure TForm1.WMGetMinMaxInfo(var MSG: Tmessage);
- // adapted from Borland Techinfo Knowledgebase tip #2865
- Begin
- inherited;
-
- with PMinMaxInfo(MSG.lparam)^ do
- begin
- with ptMinTrackSize do
- begin
- X := MINFORMWIDTH;
- Y := MINFORMHEIGHT;
- end;
- { with ptMaxTrackSize do // uncomment to restrict maximum size too
- begin
- X := 350;
- Y := 250;
- end; }
- end;
- end;
-
- procedure TForm1.UseShortDateFormatMenuItemClick(Sender: TObject);
- begin
- DATEFMT := ShortDateFormat;
- end;
-
- procedure TForm1.UseLongDateFormatMenuItemClick(Sender: TObject);
- begin
- DATEFMT := LongDateFormat;
- end;
-
- procedure TForm1.UseDaywithDateMenuItemClick(Sender: TObject);
- begin
- DATEFMT := DAYWITHDATEFMT;
- end;
-
- procedure TForm1.ToggleDateTimePickerFormat;
- begin
- if DateTimePicker1.DateFormat = dfShort then
- DateTimePicker1.DateFormat := dfLong
- else
- DateTimePicker1.DateFormat := dfShort;
- end;
-
- procedure TForm1.DateTimePicker1DblClick(Sender: TObject);
- begin
- ToggleDateTimePickerFormat;
- end;
-
- procedure TForm1.ToggleDateFormat1Click(Sender: TObject);
- begin
- ToggleDateTimePickerFormat
- end;
-
- procedure TForm1.ConfigureDateTimePicker1Click(Sender: TObject);
- begin
- if not (ConfigurationForm.visible) then
- ConfigurationForm.show;
- ConfigurationForm.BringToFront;
- end;
-
- end.
-