主要想实现的内容:
在TSpeedButton控件基础上增加一个属性btnKind,有(btnCustom, btnPrint, btnPreview)三种属性,当选择btnPrint,btnPreview对应Glyph给出一个默认的图片,这个功能在下面SetbtnKind代码已经实现。
存在问题:现在关键是:假如我选择了btnPrint,出现了一个对应的图片A,但是我认为的利用Glyph属性,重新选择了一个图片B,我希望运行是出现的是图片B而不是A,但是现在出现是图片A,不知什么原因,望给予提示,谢谢!
unit AButton;interfaceuses
SysUtils, Classes, Controls, Buttons, Windows;
type
TbtnKind = (btnCustom, btnPrint, btnPreview);type
TAButton = class(TSpeedButton)
private
FbtnKind: TbtnKind;
procedure SetbtnKind(const Value: TbtnKind);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
property btnKind: TbtnKind read FbtnKind write SetbtnKind default btnCustom;
end;procedure Register;implementation{$R AAAA.res}
{ TAButton }procedure TAButton.SetbtnKind(const Value: TbtnKind);
begin
if value <> FbtnKind then
begin
NumGlyphs := 2;
if value = btnPreview then
Glyph.LoadFromResourceName(HInstance,'PREVIEW')
else if value = btnPrint then
Glyph.LoadFromResourceName(HInstance,'PRINT');
end;
FbtnKind := Value;
end;procedure Register;
begin
RegisterComponents('Third', [TAButton]);
end;end.
在TSpeedButton控件基础上增加一个属性btnKind,有(btnCustom, btnPrint, btnPreview)三种属性,当选择btnPrint,btnPreview对应Glyph给出一个默认的图片,这个功能在下面SetbtnKind代码已经实现。
存在问题:现在关键是:假如我选择了btnPrint,出现了一个对应的图片A,但是我认为的利用Glyph属性,重新选择了一个图片B,我希望运行是出现的是图片B而不是A,但是现在出现是图片A,不知什么原因,望给予提示,谢谢!
unit AButton;interfaceuses
SysUtils, Classes, Controls, Buttons, Windows;
type
TbtnKind = (btnCustom, btnPrint, btnPreview);type
TAButton = class(TSpeedButton)
private
FbtnKind: TbtnKind;
procedure SetbtnKind(const Value: TbtnKind);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
property btnKind: TbtnKind read FbtnKind write SetbtnKind default btnCustom;
end;procedure Register;implementation{$R AAAA.res}
{ TAButton }procedure TAButton.SetbtnKind(const Value: TbtnKind);
begin
if value <> FbtnKind then
begin
NumGlyphs := 2;
if value = btnPreview then
Glyph.LoadFromResourceName(HInstance,'PREVIEW')
else if value = btnPrint then
Glyph.LoadFromResourceName(HInstance,'PRINT');
end;
FbtnKind := Value;
end;procedure Register;
begin
RegisterComponents('Third', [TAButton]);
end;end.
解决方案 »
- 关于摄像头控制视频显示区域的问题?
- delphi7如何利用DBGRID读入excle中数据?
- 求HR源码
- 一个关于TdxDBGrid编辑的问题,在线等!
- 请教我的delphi编译时出现找不到xls控件,请问是何控件啊,在哪里下载
- 数据库的优化!十万条记录!急
- 如何在程序中使dbgrid进入编辑状态?
- ado异步执行读取数据时,如果记录数多,Dbgrid无法正常显示.
- FLASH调用的问题?
- 高分求购TDBGridEh(EHLib)的源码!
- 在线等,请教!把Delphi的应用程序转换为ActiveForm组件后,怎么调试这个ocx组件?
- 当我收到的数据Numberbytes大于2048就不能接收成功,是什么原因?怎么解决。
例如:btnKind
选择btnPrint 默认出现图片A
选择btnPreview 默认出现图片B
假如btnKind我选择btnPrint,默认出现的图片是A,现在我更改这个图片是一个C,
但是在运行时回自动变为A,且关掉这个控件的Form,下次打开就变为A了。
1. property btnKind: TbtnKind read FbtnKind write SetbtnKind default btnCustom;
这个出了问题. 应该改为: Stored True;
2. 在TAButton.Create() 析构函数中.好像要加入一个什么属性状态设置. (不好意思.等查一下在上来)
你的自定义属性btnKind在Glyph后读取,而你又在btnKind的Set方法中设置了Glyph,所以你事前选定的Glyph当然就无效了。解决的方法是只在设计时设置Glyph。
或者Glyph在设计时被改动后(当然要区分是你的btnKind属性改的还是用户自己设置的)把btnKind设置成btnCustom之类的不改变Glyph的值。
////////////1. property btnKind: TbtnKind read FbtnKind write SetbtnKind ;