学习控件开发遇到的问题:取祖先类的Font域问题!

256m 2002-11-01 09:29:13
想作一个label控件,当鼠标进入的时候改变字体,离开的时候还原,但是,在create里用FCommFont.Assign(Font);保存最初的字体的时候,好象这一句没有起作用,请问这是为什么?!错在哪儿?应该怎么解决?!



unit LabelButton;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Graphics;

type
TLblBtn = class(TLabel)
private
{ Private declarations }
FActiveFont: TFont; //鼠标进入后的字体
FCommFont: TFont; //鼠标离开后正常情况的字体
FDisabledFont: TFont; //不可用时的字体
procedure SetActiveFont(value: TFont);
procedure SetDisabledFont(value: TFont);

procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;

protected
{ Protected declarations }
//procedure SetFont(Value: TFont);
public
{ Public declarations }
destructor Destroy; override;
constructor Create(aOwner: TComponent); override;
published
{ Published declarations }
property ActiveFont: TFont read FActiveFont write SetActiveFont;
property DisabledFont: TFont read FDisabledFont write SetDisabledFont;

end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Caidao', [TLblBtn]);
end;

constructor TLblBtn.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
Transparent :=true;
FActiveFont := TFont.Create;
FCommFont := TFont.Create;
FDisabledFont := TFont.Create;

FCommFont.Assign(Font); //就是这一句好象没有起作用!
end;

destructor TLblBtn.Destroy;
begin
FCommFont.Free;
FActiveFont.Free;
FDisabledFont.Free;
inherited Destroy;
end;


procedure TLblBtn.SetActiveFont(value: TFont);
begin
//if Assigned(value) then FCommFont.Assign(value);
FCommFont.Assign(value);
end;

procedure TLblBtn.SetDisabledFont(value: TFont);
begin
//if Assigned(value) then FDisabledFont.Assign(value);
FDisabledFont.Assign(value);
end;

procedure TLblBtn.CMEnabledChanged(var Message: TMessage);
begin
inherited;
if Enabled then
Font.Assign(FCommFont)
else
Font.Assign(FDisabledFont);
end;

procedure TLblBtn.CMMouseEnter(var Message: TMessage);
begin
inherited;
if Enabled then Font.Assign(FActiveFont);
end;

procedure TLblBtn.CMMouseLeave(var Message: TMessage);
begin
inherited;
if Enabled then Font.Assign(FCommFont);
end;

end.
...全文
44 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gzyzljk 2002-11-04
  • 打赏
  • 举报
回复
up,同意楼上的!
myy 2002-11-02
  • 打赏
  • 举报
回复
重载Load,写在Load里!
256m 2002-11-02
  • 打赏
  • 举报
回复
up
256m 2002-11-02
  • 打赏
  • 举报
回复
我也发现有这个问题,但是不写在create里,写在哪儿比较合适喃?
zslbg893 2002-11-02
  • 打赏
  • 举报
回复
你的代码我没详细看,但是我想告诉你,Delphi里很多过程在FormCreate事件里都不支持,比如Canvas.TextOut之类的,你可以写在其他过程里是一下
256m 2002-11-01
  • 打赏
  • 举报
回复
100分没有人要?

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧