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.
的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.