我在網上抄得如下代碼
該怎么使用此自定義控件﹖﹖﹖unit lsjEdit;interfaceuses
Messages, Windows, SysUtils, Classes, StdCtrls, Controls;
type
TlsjEdit = class(TCustomEdit)
private
FAlignment: TAlignment;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure SetAlignment(const Value: TAlignment);
public
Constructor Create(aOwner: TComponent); override;
Destructor Destroy; override;
published
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
published
property AutoSelect;
property AutoSize;
property BorderStyle;
property CharCase;
property Color;
property Ctl3D;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property MaxLength;
property OEMConvert;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;procedure Register;implementation{$R *.dcr}constructor TlsjEdit.Create(aOwner: TComponent);
begin
inherited Create(AOwner);
FAlignment := taLeftJustify;
end;Destructor TlEdit.Destroy;
begin
inherited Destroy;
end;procedure TlsjEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
case Alignment of
taLeftJustify:
Params.Style := Params.Style or LongWord(ES_Left);
taRightJustify:
Params.Style := Params.Style or LongWord(ES_Right);
else
Params.Style := Params.Style or LongWord(ES_Center);
end;
end;procedure TlsjEdit.SetAlignment(const Value: TAlignment);
begin
if (FAlignment<>Value) then
begin
FAlignment := Value;
RecreateWnd;
end;
end;procedure Register;
begin
RegisterComponents('lsjComponent', [TlsjEdit]);
end;end.
該怎么使用此自定義控件﹖﹖﹖unit lsjEdit;interfaceuses
Messages, Windows, SysUtils, Classes, StdCtrls, Controls;
type
TlsjEdit = class(TCustomEdit)
private
FAlignment: TAlignment;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure SetAlignment(const Value: TAlignment);
public
Constructor Create(aOwner: TComponent); override;
Destructor Destroy; override;
published
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
published
property AutoSelect;
property AutoSize;
property BorderStyle;
property CharCase;
property Color;
property Ctl3D;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property MaxLength;
property OEMConvert;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;procedure Register;implementation{$R *.dcr}constructor TlsjEdit.Create(aOwner: TComponent);
begin
inherited Create(AOwner);
FAlignment := taLeftJustify;
end;Destructor TlEdit.Destroy;
begin
inherited Destroy;
end;procedure TlsjEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
case Alignment of
taLeftJustify:
Params.Style := Params.Style or LongWord(ES_Left);
taRightJustify:
Params.Style := Params.Style or LongWord(ES_Right);
else
Params.Style := Params.Style or LongWord(ES_Center);
end;
end;procedure TlsjEdit.SetAlignment(const Value: TAlignment);
begin
if (FAlignment<>Value) then
begin
FAlignment := Value;
RecreateWnd;
end;
end;procedure Register;
begin
RegisterComponents('lsjComponent', [TlsjEdit]);
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货