Author: Tomas Rutkauskas How to right-align the content of a TEdit Answer: Solve 1: 1 2 procedure TESBPCSCustomEdit.CreateParams(var Params: TCreateParams); 3 begin 4 inherited CreateParams(Params); 5 case Alignment of 6 taLeftJustify: Params.Style := Params.Style or ES_LEFT; 7 taRightJustify: Params.Style := Params.Style or ES_RIGHT or ES_MultiLine; 8 taCenter: Params.Style := Params.Style or ES_CENTER or ES_MultiLine; 9 end; 10 if FReadOnly then 11 Params.Style := Params.Style or ES_READONLY; 12 end; Solve 2: 13 unit uEditEx; 14 15 interface 16 17 uses 18 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 19 StdCtrls; 20 21 type 22 TEditEx = class(TEdit) 23 private 24 FAlignment: TAlignment; 25 procedure SetAlignment(const Value: TAlignment); 26 protected 27 procedure CreateParams(var Params: TCreateParams); override; 28 public 29 published 30 constructor Create(AOwner: TComponent); override; 31 property Alignment: TAlignment 32 read FAlignment 33 write SetAlignment 34 default taLeftJustify; 35 end; 36 37 procedure register; 38 39 implementation 40 41 {R uEditEx.dcr} 42 43 procedure register; 44 begin 45 RegisterComponents('gate(n)etwork', [TEditEx]); 46 end; 47 48 { TEditEx } 49 50 constructor TEditEx.Create(AOwner: TComponent); 51 begin 52 inherited Create(AOwner); 53 FAlignment := taLeftJustify; 54 end; 55 56 procedure TEditEx.CreateParams(var Params: TCreateParams); 57 const 58 Alignments: array[TAlignment] of Cardinal = 59 (ES_LEFT, ES_RIGHT, ES_CENTER); 60 begin 61 inherited CreateParams(Params); 62 Params.Style := Params.Style or {ES_MULTILINE or} Alignments[FAlignment]; 63 end; 64 65 procedure TEditEx.SetAlignment(const Value: TAlignment); 66 begin 67 if FAlignment <> Value then 68 begin 69 FAlignment := Value; 70 RecreateWnd; 71 end; 72 end; 73 74 end.