按 F12 切換到程式碼編輯模式
type
TCalendar = class(Calendar.TCalendar)
private
// 定義一個 2 維陣列記錄日曆內的每個 cell 是否要顯示特定顏色
fSel : array[0..6,0..5]of Boolean;
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
end;
重新宣告 TCalendar, 繼承自 Calendar.TCalendar, 並 override(覆寫) DrawCell procedure
{$R *.dfm}
procedure TCalendar.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
begin
if fSel[ACol,ARow] then
Canvas.Brush.Color := clRed;
Inherited;
end;
在 button1 的 OnClick 事件裡寫入要變色的 cell
procedure TForm1.Button1Click(Sender: TObject);
begin
calendar1.fSel[1,1] := true;
calendar1.fSel[2,2] := true;
calendar1.fSel[3,3] := true;
calendar1.fSel[4,4] := true;
calendar1.Refresh;
end;
沒有留言:
張貼留言