Jak wyjustować tekst w TEdit
AdamPL
type
TAlignment = (taLeftJustify, taRightJustify, taCenter);
TMyEdit = class(TEdit)
private
FAlignment: TAlignment;
procedure SetAlignment(Value: TAlignment);
protected
procedure CreateParams(var Params: TCreateParams); override;
published
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
end;
implementation
{ TMyEdit }
procedure TMyEdit.CreateParams(var Params: TCreateParams);
const
Styles : Array [TAlignment] of DWORD =
(ES_LEFT, ES_RIGHT, ES_CENTER );
begin
inherited;
Params.Style := Params.Style or Styles[ FAlignment ];
end;
procedure TMyEdit.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
RecreateWnd;
end;
end;
Dynamiczne tworzenie i wywołanie komponentu TMyEdit:
procedure TForm1.FormCreate(Sender: TObject);
begin
MyEdit1:= TMyEdit.Create(Self);
MyEdit1.Parent:= Self;
MyEdit1.Alignment:= taCenter; //justowanie tekstu
MyEdit1.Left:= 10;
MyEdit1.Top:= 10;
end;