使文字具有左、中、右对齐属性的Edit控件挺多,自己实现也不难,但要具有Transparent和Layout这样属性的,
需要从TControl类继承,难度太大:(
下面这个是我试着做的,已经可以实现文字的左、中、右对齐了,你看看吧
unit EditEh;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls;
type
TEditEh = class(TCustomEdit)
private
FAlignment: TAlignment;
procedure SetAlignment(Value: TAlignment);
protected
procedure CreateParams(var Params: TCreateParams); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Alignment: TAlignment read FAlignment write SetAlignment
default taLeftJustify;
property Height;
property Anchors;
property AutoSelect;
property AutoSize;
property BiDiMode;
property BorderStyle;
property CharCase;
property Color;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property ImeMode;
property ImeName;
property MaxLength;
property OEMConvert;
property ParentBiDiMode;
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 OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MyLab', [TEditEh]);
end;
{ TEditEh }
constructor TEditEh.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
procedure TEditEh.CreateParams(var Params: TCreateParams);
const
Alignments: array [TAlignment] of DWord = (ES_LEFT, ES_RIGHT, ES_CENTER);
begin
inherited CreateParams(Params);
CreateSubClass(Params, 'EDITEH');
with Params do
Style := Params.Style or ES_MULTILINE or Alignments[FAlignment];
end;
destructor TEditEh.Destroy;
begin
inherited Destroy;
end;
procedure TEditEh.SetAlignment(Value: TAlignment);
var
OldHeight: Integer;
begin
if FAlignment <> Value then
begin
OldHeight := Height;
FAlignment := Value;
RecreateWnd;
Height := OldHeight;
end;
end;
end.