在自定义控件中使用SpeedButton,如何设置SpeedButton的Glyph属性?(200分)

  • 主题发起人 主题发起人 lichaogang
  • 开始时间 开始时间
L

lichaogang

Unregistered / Unconfirmed
GUEST, unregistred user!
我自己写了一个控件在其中创建了几个SpeedButton,为了可以在设计期能够编辑这几个SpeedButton
的Glyph属性,我定义了几个Bitmap的对象,并将它们做成Publish属性。
在设计期,设置几个Bitmap属性后可以立即看到效果,但在运行期却不显示Bitmap,应该如何
做才可以在设计期和运行期都可以看到Bitmap?
请各位大侠指教,代码如下。
运行期包内容:
________________________________________________________________
unit WizardCtrolR;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Forms,
Buttons, Controls, ExtCtrls;


type
TBackNextClickEvent = procedure(Sender: TObject; var AllowChange: Boolean) of object;

type
TWizardCtrl = class(TCustomControl)
private
{ Private declarations }
FHelpButton: TSpeedButton;
FBackButton: TSpeedButton;
FNextButton: TSpeedButton;
FCancelButton: TSpeedButton;
FHelpBitmap: TBitMap;
FBackBitmap: TBitMap;
FNextBitmap: TBitMap;
FCancelBitmap: TBitMap;
FFinishBitmap: TBitMap;

procedure SetHelpBitmap(bitmap: TBitmap);
procedure SetBackBitmap(bitmap: TBitmap);
procedure SetNextBitmap(bitmap: TBitmap);
procedure SetCancelBitmap(bitmap: TBitmap);
procedure SetFinishBitmap(bitmap: TBitmap);
protected
{ Protected declarations }
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure Paint; override;
procedure Resize; override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

published
{ Published declarations }
property HelpBitmap: TBitMap read FHelpBitmap write SetHelpBitmap;
property BackBitmap: TBitMap read FBackBitmap write SetBackBitmap;
property NextBitmap: TBitMap read FNextBitmap write SetNextBitmap;
property CancelBitmap: TBitMap read FCancelBitmap write SetCancelBitmap;
property FinishBitmap: TBitMap read FFinishBitmap write SetFinishBitmap;
end;

implementation

constructor TWizardCtrl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Align := alBottom;
Height := 48;

FButtonFlat:=True;

FHelpVisible := True;
FHelpLeftAlign := False;
FFinished := False;
FPageName := '';
BorderWidth := 7;

FHelpButton := TSpeedButton.Create(Self);
FHelpButton.Parent := Self;
FHelpButton.OnClick := HelpButtonClick;
FHelpButton.Width := 75;
FHelpButton.Height := 23;
FHelpButton.Flat := ButtonFlat;
CaptionOfHelp := '&Help';

FBackButton := TSpeedButton.Create(Self);
FBackButton.Parent := Self;
FBackButton.OnClick := BackButtonClick;
FBackButton.Width := 75;
FBackButton.Height := 23;
FBackButton.Flat := ButtonFlat;
CaptionOfBack := '< Back(&B)';

FNextButton := TSpeedButton.Create(Self);
FNextButton.Parent := Self;
FNextButton.OnClick := NextButtonClick;
FNextButton.Width := 75;
FNextButton.Height := 23;
FNextButton.Flat := ButtonFlat;
CaptionOfNext := 'Next(&N) >';
CaptionOfFinish := 'Finish(&F)';

FCancelButton := TSpeedButton.Create(Self);
FCancelButton.Parent := Self;
FCancelButton.OnClick := CancelButtonClick;
FCancelButton.Width := 75;
FCancelButton.Height := 23;
FCancelButton.Flat := ButtonFlat;
CaptionOfCancel := 'Cancel(&C)';

FHelpBitmap := TBitmap.Create;
FBackBitmap := TBitmap.Create;
FNextBitmap := TBitmap.Create;
FCancelBitmap := TBitmap.Create;
FFinishBitmap := TBitmap.Create;
end;

destructor TWizardCtrl.Destroy;
begin
FHelpButton.Free;
FBackButton.Free;
FNextButton.Free;
FCancelButton.Free;

FHelpBitmap.Free;
FBackBitmap.Free;
FNextBitmap.Free;
FCancelBitmap.Free;
FFinishBitmap.Free;
inherited Destroy;
end;
procedure TWizardCtrl.SetHelpBitmap(bitmap: TBitmap);
begin
FHelpBitmap.Assign(Bitmap);
FHelpButton.Glyph:=FHelpBitmap;
Invalidate;
end;

procedure TWizardCtrl.SetBackBitmap(bitmap: TBitmap);
begin
FBackBitmap.Assign(Bitmap);
FBackButton.Glyph.Assign(Bitmap);
Invalidate;
end;

procedure TWizardCtrl.SetNextBitmap(bitmap: TBitmap);
begin
FNextBitmap.Assign(Bitmap);
FNextButton.Glyph.Assign(Bitmap);
Invalidate;
end;

procedure TWizardCtrl.SetCancelBitmap(bitmap: TBitmap);
begin
FCancelBitmap.Assign(Bitmap);
FCancelButton.Glyph.Assign(Bitmap);
Invalidate;
end;

procedure TWizardCtrl.SetFinishBitmap(bitmap: TBitmap);
begin
FFinishBitmap.Assign(Bitmap);
if FFinished then
FNextButton.Glyph.Assign(Bitmap);
Invalidate;
end;

end.

设计期包内容:
__________________________________________________________________

unit WizardCtrolD;

interface
uses SysUtils,Classes,DesignIntf, DesignEditors;
type

TBitmapEditor = class(TDefaultEditor)
protected
procedure EditProperty(const Prop: IProperty; var Continue: Boolean); override;
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
procedure Register;

implementation
uses WizardCtrolR;

procedure Register;
begin
RegisterComponents('Samples', [TWizardCtrl]);
RegisterComponentEditor(TWizardCtrl, TBitmapEditor);
end;

procedure TBitmapEditor.EditProperty(const Prop: IProperty;
var Continue: Boolean);
var
PropName: string;
begin
PropName := Prop.GetName;
if (CompareText(PropName, 'HelpBitmap') = 0)
or (CompareText(PropName, 'BackBitmap') = 0)
or (CompareText(PropName, 'NextBitmap') = 0)
or (CompareText(PropName, 'FinishBitmap') = 0)
or (CompareText(PropName, 'CancelBitmap') = 0) then
begin
Prop.Edit;
Continue := False;
end;
end;

function TBitmapEditor.GetVerbCount: Integer;
begin
Result := 1;
end;

function TBitmapEditor.GetVerb(Index: Integer): string;
begin
if Index = 0 then
Result := 'Load Bitmap'
else Result := '';
end;

procedure TBitmapEditor.ExecuteVerb(Index: Integer);
begin
if Index = 0 then Edit;
end;
end.
 
published 一个Glyph的属性!
 
mark all publish to published
 
设计期都能看见,运行期还看不见?
 
其实你不用这么复杂,
publish
property HelpButton : TSpeedButton read FHelpButton write FHelpButton;

这样你在设计期就可以直接对他进行编辑,运行企业可以直接访问
 
同意Del_Sun
 
To Del_Sun:
如果这样的话就是在使用控件的时候才指定SpeedButton,也就是说SpeedButton与本控件是分离的,
我是想将SpeedButton做在控件中,不用再为它指定SpeedButton,只需指定它的Glyph即可。
To wlmmlw:
你说的Glyph是什么属性的?是不是Bitmap?我已经Published了几个Bitmap的属性,并将这几个
Bitmap的属性分别赋给了SpeedButton的Glyph属性了,在设计期可以看到SpeedButton上的图片,
但程序一运行就看不到了。
To All:
多谢大家,我以前没有怎么写过控件,请大家说详细一点。
 
这个问题我已经解决了,主要是要重载TCustomControl的Paint方法。
开始发分了!
多谢大家!
 
后退
顶部