继承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 点击打开链接