?? umonthpanel.~pas
字號:
unit uMonthPanel;
{$R *.res}
interface
uses
StdCtrls,SysUtils,Controls,ExtCtrls,Graphics,Grids,Classes,
Messages,Windows,DateUtils,Menus,Buttons;
CONST
SOLAR_TERM: Array[0..23] of string =('小寒','大寒','立春','雨水','驚蟄','春分',
'清明','谷雨','立夏','小滿','芒種','夏至','小暑',
'大暑','立秋','處暑','白露','秋分','寒露','霜降','立冬','小雪','大雪','冬至');
//國歷節(jié)日 *表示放假日
SUNHOLIDY: Array[0..40] of string =(
'0101*元旦節(jié)',
'0214 情人節(jié)',
'0305 學(xué)雷鋒紀(jì)念日',
'0308 婦女節(jié)',
'0312 植樹節(jié)',
'0315 消費(fèi)者權(quán)益日',
'0401 愚人節(jié)',
'0407 世界衛(wèi)生日',
'0422 世界地球日',
'0501*勞動節(jié)',
'0504 青年節(jié)',
'0508 世界紅十字日',
'0512 國際護(hù)士節(jié)',
'0515 國際家庭日',
'0517 國際電信日',
'0601 國際兒童節(jié)',
'0605 世界環(huán)境保護(hù)日',
'0606 全國愛眼日',
'0625 全國土地日',
'0626 國際禁毒日',
'0701 香港回歸紀(jì)念日 中共誕辰',
'0707 抗日戰(zhàn)爭紀(jì)念日',
'0801 建軍節(jié)',
'0815 抗日戰(zhàn)爭勝利紀(jì)念',
'0909 毛澤東逝世紀(jì)念',
'0908 國際掃盲日',
'0910 中國教師節(jié)',
'0927 世界旅游日',
'0928 孔子誕辰',
'1001*國慶節(jié)',
'1006 老人節(jié)',
'1009 世界郵政日',
'1014 世界標(biāo)準(zhǔn)日',
'1016 世界糧食日',
'1024 聯(lián)合國日',
'1120*彝族年',
'1112 孫中山誕辰紀(jì)念',
'1205 國際志愿人員日',
'1220 澳門回歸紀(jì)念',
'1225 Christmas Day',
'1226 毛澤東誕辰紀(jì)念');
//農(nóng)歷節(jié)日 *表示放假日
MONTHHOLIDY: Array[0..10] of string =(
'0101*春節(jié)',
'0115 元宵節(jié)',
'0505 端午節(jié)',
'0624*火把節(jié)',
'0707 七夕情人節(jié)',
'0715 中元節(jié)',
'0815 中秋節(jié)',
'0909 重陽節(jié)',
'1208 臘八節(jié)',
'1224 小年',
'0100 除夕');
//某月的第幾個星期幾
WEEKHOLIDY: Array[0..3] of string =(
'0520 母親節(jié)',
'0630 父親節(jié)',
'0730 被奴役國家周',
'1144 Thanksgiving感恩節(jié)') ;
CHWEEKSTRING: array[0..6] of string =('星期一','星期二','星期三','星期四','星期五','星期六','星期日');
WM_MONTHPANELRESIZE = WM_USER + 1;
MP_MINWIDTH = 359;
MP_MINHEIGHT = 137;
CALENDARSPLITE = '-';
type
{
dsNormal:工作日,包括周末的工作日
dsHoliday:節(jié)假日,包括周末的節(jié)假日
dsWeekend:正常周末
}
TDaySign = (dsNormal,dsHoliday,dsWeekend);
TOnDaySignChangedEvent = procedure (Sender: TObject; ChangedDate:TDate;ToSign:TDaySign) of object;
TOnDaysSignChangedEvent = procedure (Sender: TObject; ChangeCellRange:TGridRect;ToSign:TDaySign) of object;
TMonthPanel = class(TPanel)
private
FWeekendCaptionColor: TColor;
FWeekendColor: TColor;
FWeekendTextColor: TColor;
FNormalColor: TColor;
FNormalTextColor: TColor;
FHolidayTextColor: TColor;
FHolidayColor: TColor;
FChineseNewYear:TDate;
FGridPopupMenu: TPopupMenu;
FRedrawing:Boolean;
FDaysInMonth:Integer;
FMonthPanelDate: TDate;
FDaySigns : array[1..31] of TDaySign;
FDayInfors : array[1..31] of string;
FCellDays : array [0..6,1..6] of TDate; //根據(jù)格子找到代表的日期
FDayCells : array [1..31] of TGridCoord; //根據(jù)日子找到格子
FOnDaySignChanged: TOnDaySignChangedEvent;
FDispalyChineseDay: Boolean;
FOnDaysSignChanged: TOnDaysSignChangedEvent;
FGregorianCalendarFont: TFont;
FLunarCalendarFont: TFont;
FShowMonthChangeButton: Boolean;
procedure ClearCellDays;
procedure ClearDayCells;
procedure SelfResize(Sender: TObject);
procedure DoWM_Resize(var Msg: TMessage); message WM_MONTHPANELRESIZE;
procedure MonthGridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure MonthGridMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure MonthGridDblClick(Sender: TObject);
procedure SelectedRangeToSign(ToSign:TDaySign);
procedure ToHolidayPopupMenuClicked(Sender: TObject);
procedure ToNormalDayPopupMenuClicked(Sender: TObject);
procedure ToNormalWeekEndPopupMenuClicked(Sender: TObject);
procedure DisplayCDPopupMenuClicked(Sender: TObject);
procedure OnPriClick(Sender: TObject);
procedure OnNexClick(Sender: TObject);
procedure SetMonthCaptionHeight(const Value: Integer);
procedure SetColWidth(const Value: Integer);
procedure SetRowHeight(const Value: Integer);
procedure SetWeekendCaptionColor(const Value: TColor);
procedure SetWeekendColor(const Value: TColor);
procedure SetWeekendTextColor(const Value: TColor);
procedure SetNormalColor(const Value: TColor);
procedure SetNormalTextColor(const Value: TColor);
procedure SetHolidayColor(const Value: TColor);
procedure SetHolidayTextColor(const Value: TColor);
function GetMonthCaptionHeight: Integer;
function GetRowHeight: Integer;
function GetColWidth: Integer;
function GetMonthCaptionColor: TColor;
procedure SetMonthCaptionColor(const Value: TColor);
function GetMonthCaptionFont: TFont;
procedure SetMonthCaptionFont(const Value: TFont);
procedure SetOnCaptionDBClick(const Value: TNotifyEvent);
function GetCaptionPopUpMenu: TPopupMenu;
procedure SetCaptionPopUpMenu(const Value: TPopupMenu);
function GetCaptionMouseMove: TMouseMoveEvent;
procedure SetCaptionMouseMove(const Value: TMouseMoveEvent);
function GetOnCaptionDBClick: TNotifyEvent;
function GetOnCaptionMouseDown: TMouseEvent;
function GetOnCaptionMouseUp: TMouseEvent;
procedure SetOnCaptionMouseDown(const Value: TMouseEvent);
procedure SetOnCaptionMouseUp(const Value: TMouseEvent);
procedure SetMonthPanelDate(const Value: TDate);
procedure SetDispalyChineseDay(const Value: Boolean);
{刷新grid顯示,返回最后一周在本月周數(shù)}
function RefreshMonthGrid:Integer;
procedure SetCalendarLunarFont(const Value: TFont);
procedure SetGregorianCalendarFont(const Value: TFont);
procedure SetMonthChangeButton(const Value: Boolean);
protected
FMonthGrid:TStringGrid;
FMonthCaptionPanel:TPanel;
FLeftCaption:TLabel;
FPriMonth:TSpeedButton;
FNexMonth:TSpeedButton;
//根據(jù)設(shè)定的各種尺寸大小重新擺放控件的位置以及設(shè)定大小
procedure ReDrawPanel(ResizeSelf:Boolean = True);
procedure PreparePopMenu;
public
constructor Create(AOwner: TComponent);override;
destructor Destroy;override;
{設(shè)置當(dāng)月每一天為非節(jié)假日}
procedure ClearDaySigns;
{清空當(dāng)月每一天說明文字}
procedure ClearDayInfors;
procedure SetDaySign(DayIndex:Integer;DaySign:TDaySign);
procedure SetDayInfor(DayIndex:Integer;DayInfor:string);
function DaySigns(DayIndex:Integer) : TDaySign;
function DayInfors(DayIndex:Integer) : string;
function CellDay(ACellCoord:TGridCoord):TDate; //根據(jù)格子找到代表的日期
function DayCell(DayIndex:Integer) :TGridCoord; //根據(jù)日子找到格子
published
property ShowMonthChangeButton:Boolean read FShowMonthChangeButton
write SetMonthChangeButton;
property GregorianCalendarFont:TFont read FGregorianCalendarFont
write SetGregorianCalendarFont;
property LunarCalendarFont:TFont read FLunarCalendarFont
write SetCalendarLunarFont;
property MonthCaptionHeight:Integer read GetMonthCaptionHeight
write SetMonthCaptionHeight default 20;
property MonthCaptionColor:TColor read GetMonthCaptionColor
write SetMonthCaptionColor default clBackground;
property MonthCaptionFont:TFont read GetMonthCaptionFont
write SetMonthCaptionFont;
property ColWidth:Integer read GetColWidth write SetColWidth default 50;
property RowHeight:Integer read GetRowHeight write SetRowHeight default 16;
property WeekendCaptionColor:TColor read FWeekendCaptionColor
write SetWeekendCaptionColor default clBlue;
property WeekendColor:TColor read FWeekendColor
write SetWeekendColor default clBlue;
property WeekendTextColor:TColor read FWeekendTextColor
write SetWeekendTextColor default clRed;
property NormalColor:TColor read FNormalColor
write SetNormalColor default clWindow;
property NormalTextColor:TColor read FNormalTextColor
write SetNormalTextColor default clWindowText;
property HolidayColor:TColor read FHolidayColor
write SetHolidayColor default clGreen;
property HolidayTextColor:TColor read FHolidayTextColor
write SetHolidayTextColor default clBlue;
{MonthPanel所顯示的年月}
property MonthPanelDate :TDate read FMonthPanelDate Write SetMonthPanelDate;
property OnDaySignChanged:TOnDaySignChangedEvent read FOnDaySignChanged write FOnDaySignChanged;
property OnDaysSignChanged:TOnDaysSignChangedEvent read FOnDaysSignChanged write FOnDaysSignChanged;
property OnCaptionDBClick: TNotifyEvent read GetOnCaptionDBClick write SetOnCaptionDBClick;
property OnCaptionMouseMove: TMouseMoveEvent read GetCaptionMouseMove write SetCaptionMouseMove;
property OnCaptionMouseDown: TMouseEvent read GetOnCaptionMouseDown write SetOnCaptionMouseDown;
property OnCaptionMouseUp: TMouseEvent read GetOnCaptionMouseUp write SetOnCaptionMouseUp ;
property CaptionPopUpMenu: TPopupMenu read GetCaptionPopUpMenu write SetCaptionPopUpMenu;
property DispalyChineseDay:Boolean read FDispalyChineseDay write SetDispalyChineseDay;
end;
procedure Register;
implementation
uses uMoon,StrUtils;
procedure Register;
begin
RegisterComponents('GiSun', [TMonthPanel]);
end;
function GetFontStringSize(Font:TFont;Caption:string):Integer;
var
SizeLabel:TLabel;
begin
SizeLabel := Tlabel.Create(nil);
try
SizeLabel.Font.Assign(Font);
SizeLabel.AutoSize := True;
SizeLabel.Caption := Caption;
Result := SizeLabel.Width;
finally
SizeLabel.Free;
end;
end;
{ TMonthPanel }
constructor TMonthPanel.Create(AOwner: TComponent);
var
i:Integer;
begin
inherited;
FShowMonthChangeButton := False;
FLunarCalendarFont := TFont.Create;
FGregorianCalendarFont := TFont.Create;
Self.ParentCtl3D := False;
Self.ParentFont := False;
Self.Font.Name := '宋體';
Self.Font.Height := -12;
Self.Font.Charset := GB2312_CHARSET;
FGregorianCalendarFont.Assign(Self.Font);
FGregorianCalendarFont.Name := '宋體';
FLunarCalendarFont.Assign(Self.Font);
FLunarCalendarFont.Name := '楷體_GB2312';
FLunarCalendarFont.Size := FGregorianCalendarFont.Size-1;
FDispalyChineseDay := False;
FRedrawing := False;
FWeekendColor := clBlue;
FHolidayTextColor := clBlue;
FHolidayColor := clMoneyGreen;
FNormalColor := clWindow;
FNormalTextColor := clWindowText;
FGridPopupMenu := TPopupMenu.Create(Self);
FMonthGrid := TStringGrid.Create(Self);
FMonthCaptionPanel := TPanel.Create(Self);
FLeftCaption := TLabel.Create(Self);
FLeftCaption.Parent := FMonthCaptionPanel;
FLeftCaption.Align := alLeft;
FPriMonth := TSpeedButton.Create(Self);
FNexMonth := TSpeedButton.Create(Self);
FPriMonth.Width := 15;
FNexMonth.Width := 15;
FPriMonth.Height := 15;
FNexMonth.Height := 15;
FPriMonth.Caption := '<';
FNexMonth.Caption := '>';
FPriMonth.OnClick := OnPriClick;
FNexMonth.OnClick := OnNexClick;
FPriMonth.Parent := FMonthCaptionPanel;
FNexMonth.Parent := FMonthCaptionPanel;
FPriMonth.Visible := False;
FNexMonth.Visible := False;
FMonthCaptionPanel.Color := clTeal;
FMonthCaptionPanel.Alignment := taRightJustify;
FMonthCaptionPanel.Font.Name := '宋體';
FMonthCaptionPanel.Font.Size := -9;
FMonthCaptionPanel.Font.Color := clYellow;
FMonthCaptionPanel.Font.Style := FMonthCaptionPanel.Font.Style + [fsBold];
Self.Ctl3D := False;
FMonthGrid.Ctl3D := False;
FMonthCaptionPanel.Ctl3D := False;
FMonthGrid.Parent := Self;
FMonthCaptionPanel.Parent := Self;
FMonthGrid.FixedRows := 1;
FMonthGrid.FixedCols := 0;
FMonthGrid.ColCount := 7;
FMonthGrid.RowCount := 7;
for i := 0 to 6 do
begin
FMonthGrid.Cells[i,0] := CHWEEKSTRING[i];
end;
ClearDaySigns;
ClearDayInfors;
FMonthCaptionPanel.Left := 0;
FMonthCaptionPanel.Top := 0;
FMonthCaptionPanel.Height := 17;
FMonthGrid.Left := 0;
FMonthGrid.DefaultColWidth := 50;
FMonthGrid.DefaultRowHeight := 16;
FWeekendCaptionColor := clBlue;
FWeekendTextColor := clRed;
FWeekendColor := clWindow;
ReDrawPanel;
PreparePopMenu;
FMonthGrid.PopupMenu := FGridPopupMenu;
FMonthGrid.OnDrawCell := MonthGridDrawCell;
FMonthGrid.OnMouseMove := MonthGridMouseMove;
FMonthGrid.OnDblClick := MonthGridDblClick;
Self.OnResize := SelfResize;
end;
destructor TMonthPanel.Destroy;
begin
FPriMonth.Free;
FNexMonth.Free;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -