吴
吴辽
Unregistered / Unconfirmed
GUEST, unregistred user!
我需要开发一个具有阴影的一个按钮控件,我用了两个panel 重叠,就象ghost6。0中
的那种按钮,外面一个用亮色,里面一个用暗色(表示阴影),当我在外面panel按下mouse时时,
我将两个控件重合,当松开mouse时,恢复原状。
请教各位及格问题:
1.我是继承自tpanel,进行开发,还是twincontrol开发。
2.我如何写mousedown事件,现在是这样的情况:
我写出来的那个onmousedown事件,然后我用一个程序来测试该组件,我发现我如果
不在测试程序中该按钮的mousedown写一句语句(随便什么语句,比如showmessage(''aa)之类的)
这个组件的setOnMousedown过程不执行,如果写一条语句,那么你还没点击该按钮时,这个过程就
执行了,这是怎么会事,我把程序代码贴出来,大家帮帮忙。谢谢了!!!
unit ShadowButton;
interface
uses
Windows, Messages, SysUtils,StdCtrls, Classes, Controls, ExtCtrls,Graphics;
type
TShadowButton = class(twincontrol)
private
FPanelOutside:tpanel;
FpanelInside:tpanel;
{ Private declarations }
protected
procedure wmsize(var message:twmsize);message wm_size;
function GetOnMousedown:tmouseevent;
procedure SetOnMousedown(value :tmouseevent);
{ Protected declarations }
public
constructor create(Aowner:tcomponent);override;
destructor destroy;override;
{ Public declarations }
published
property Onmousedown:tmouseevent read getonmousedown write setonmousedown;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TShadowButton]);
end;
constructor Tshadowbutton.create(Aowner:tcomponent);
begin
inherited create(aowner);
bevelouter:=bvnone;
fpaneloutside:=tpanel.Create(self);
fpanelinside:=tpanel.Create(self);
with fpanelinside do
begin
Parent:=self;
Color :=clblack;
bevelouter:=bvNone;
Left :=fpaneloutside.Left +8;
top:=fpaneloutside.Top +8;
width:=fpaneloutside.Width;
height:=fpanelinside.Height ;
end;
fpaneloutside.Parent:=self;
fpaneloutside.Color :=clblue;
fpaneloutside.bevelouter:=bvNone;
width:=fpaneloutside.Width;
height:=fpanelinside.Height ;
end;
procedure tshadowbutton.wmsize(var message:twmsize);
begin
inherited;
fpaneloutside.Width :=message.Width-15;
fpaneloutside.Height :=message.Height-15;
fpanelinside.Width :=message.Width-15;
fpanelinside.Height :=message.Height-15;
end;
destructor tshadowbutton.destroy;
begin
fpanelinside.Free;
fpaneloutside.Free;
inherited destroy;
end;
function tshadowbutton.GetOnMousedown:tmouseevent;
begin
result :=fpaneloutside.OnMouseDown;
end;
//就在这个过程里面里出问题。
procedure tshadowbutton.setOnMousedown(value:tmouseevent);
begin
fpaneloutside.OnMouseDown :=value;
fpaneloutside.Left :=fpanelinside.Left;
fpaneloutside.top :=fpanelinside.top;
end;
的那种按钮,外面一个用亮色,里面一个用暗色(表示阴影),当我在外面panel按下mouse时时,
我将两个控件重合,当松开mouse时,恢复原状。
请教各位及格问题:
1.我是继承自tpanel,进行开发,还是twincontrol开发。
2.我如何写mousedown事件,现在是这样的情况:
我写出来的那个onmousedown事件,然后我用一个程序来测试该组件,我发现我如果
不在测试程序中该按钮的mousedown写一句语句(随便什么语句,比如showmessage(''aa)之类的)
这个组件的setOnMousedown过程不执行,如果写一条语句,那么你还没点击该按钮时,这个过程就
执行了,这是怎么会事,我把程序代码贴出来,大家帮帮忙。谢谢了!!!
unit ShadowButton;
interface
uses
Windows, Messages, SysUtils,StdCtrls, Classes, Controls, ExtCtrls,Graphics;
type
TShadowButton = class(twincontrol)
private
FPanelOutside:tpanel;
FpanelInside:tpanel;
{ Private declarations }
protected
procedure wmsize(var message:twmsize);message wm_size;
function GetOnMousedown:tmouseevent;
procedure SetOnMousedown(value :tmouseevent);
{ Protected declarations }
public
constructor create(Aowner:tcomponent);override;
destructor destroy;override;
{ Public declarations }
published
property Onmousedown:tmouseevent read getonmousedown write setonmousedown;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TShadowButton]);
end;
constructor Tshadowbutton.create(Aowner:tcomponent);
begin
inherited create(aowner);
bevelouter:=bvnone;
fpaneloutside:=tpanel.Create(self);
fpanelinside:=tpanel.Create(self);
with fpanelinside do
begin
Parent:=self;
Color :=clblack;
bevelouter:=bvNone;
Left :=fpaneloutside.Left +8;
top:=fpaneloutside.Top +8;
width:=fpaneloutside.Width;
height:=fpanelinside.Height ;
end;
fpaneloutside.Parent:=self;
fpaneloutside.Color :=clblue;
fpaneloutside.bevelouter:=bvNone;
width:=fpaneloutside.Width;
height:=fpanelinside.Height ;
end;
procedure tshadowbutton.wmsize(var message:twmsize);
begin
inherited;
fpaneloutside.Width :=message.Width-15;
fpaneloutside.Height :=message.Height-15;
fpanelinside.Width :=message.Width-15;
fpanelinside.Height :=message.Height-15;
end;
destructor tshadowbutton.destroy;
begin
fpanelinside.Free;
fpaneloutside.Free;
inherited destroy;
end;
function tshadowbutton.GetOnMousedown:tmouseevent;
begin
result :=fpaneloutside.OnMouseDown;
end;
//就在这个过程里面里出问题。
procedure tshadowbutton.setOnMousedown(value:tmouseevent);
begin
fpaneloutside.OnMouseDown :=value;
fpaneloutside.Left :=fpanelinside.Left;
fpaneloutside.top :=fpanelinside.top;
end;