繼承Tcalendar控件,讓當天日期醒目顯示

繼承Tcalendar控件,讓當天日期醒目顯示

    一、新建一控件

    打開Delphi主菜單Cpmponent—New Cpmponent:


    二、配置參數

.        

    點擊OK鍵,打開Unit單元文件。

    三、修改單元文件

unit LyCalendar;


interface

 

uses

 Windows,

 Messages, SysUtils, Variants, Classes, Graphics, Controls, //Forms,

 Dialogs, Grids, Calendar, ComCtrls, StdCtrls,DateUtils;

 

type

 TLyCalendar = class(TCalendar)

 private

    {Private declarations }

 protected

    {Protected declarations }

   procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState:TGridDrawState); override;

 public

    {Public declarations }

 published

    {Published declarations }

 end;

 

procedure Register;

 

implementation

 

procedure Register;

begin

 RegisterComponents('LyComMy', [TLyCalendar]);

end;

 

procedure TLyCalendar.DrawCell(ACol, ARow:Integer; ARect: TRect; AState: TGridDrawState);

var  TheText: string;

    vDay: string;

begin

 TheText := CellText[ACol, ARow];

 vDay := IntToStr(DateUtils.DayOf(Now));

  ifvDay = TheText then

 begin

    //當天顯示樣式

   Canvas.Font.Color := clRed;

   Canvas.Font.Style:=Canvas.Font.Style+[fsBold];

  end

 else begin

    //被選擇日期顯示樣式

   if  (gdSelected in AState) or(gdFocused in AState) then

   begin

     Canvas.Brush.Color := clBlue;

   end;

 end;

 inherited;

end;

 

end.

    四、安裝控件

    1、將新的單元文件,存入C:\ProgramFiles\Borland\Delphi7\Projects\Bpl\ 目錄;

    2、打開Delphi主菜單Cpmponent—Insert  Cpmponent:

 

    3、指定安裝的參數:

 

    按“OK”鍵,打開對話框:

 

    按“compile”鍵,完成安裝。

    四、新的控件樣式:


    五、源碼下載地址:http://download.csdn.net/detail/lyhoo163/9631356  點擊打開鏈接

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章