azteroth
Here is a way to create a right justified edit box. I copied liberally from the Jedi Code for the JVEdit component (free from their home page at:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TRightEdit = class(TEdit)
private
FAlignment: TAlignment;
public
procedure Justify(NewAlignment: TAlignment);
constructor Create(AOwner: TComponent); override;
published
procedure CreateParams(var Params: TCreateParams); override;
property Alignment: TAlignment read FAlignment write FAlignment default taLeftJustify;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
RightEdit: TRightEdit;
implementation
{$R *.dfm}
// TRightEdit ***************************************************************
constructor TRightEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Parent := TWinControl(AOwner);
end;
procedure TRightEdit.Justify(NewAlignment: TAlignment);
var
FOldEvent: TNotifyEvent;
begin
FOldEvent := OnExit;
try
OnExit := nil;
if FAlignment <> NewAlignment then
begin
FAlignment := NewAlignment;
RecreateWnd;
end;
finally
OnExit := FOldEvent;
end;
end;
procedure TRightEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
if Parent <> nil then
case FAlignment of
taLeftJustify:
Params.Style := Params.Style or ES_LEFT;
taRightJustify:
Params.Style := Params.Style or ES_RIGHT;
taCenter:
Params.Style := Params.Style or ES_CENTER;
end;
end;
// Form1 **********************************************************************
procedure TForm1.Button1Click(Sender: TObject);
begin
RightEdit.Justify(taRightJustify);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RightEdit := TRightEdit.Create(Form1);
with RightEdit do
begin
Text := 'Right Justify';
Left := 200;
Top := 200;
Width := 300;
Height := 20;
Enabled := true;
Refresh;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
RightEdit.Free;
end;
end.