Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alignment of text

Status
Not open for further replies.

azteroth

Programmer
Jun 16, 2002
3
US
in the editbox how do i get the text to align on the right instead of on the left

thanx ahead
~azteroth~
 
See thats what i thought too was to use the alignment property but i looked every where for that and couldn't find anything to align the text in the edit1 box.

~azteroth~
 
Make sure that you see ALL properties in Object Inspector. Alignment property does exist fo TEditBox. Right click on the object inspector and in "View" submenu check "Visual" (if it's unchecked). Hope that helps.

--- markus
 
Azteroth is right you know; I'm lookin', and I ain't seein'. McMerfy, are you sure you haven't got some crazy non-standard TEdit-replacement installed?

Azteroth, if you need right-align, you can use a TLabel. If you need right-align on an actual edit box, maybe a right-aligned oneline TMemo.

Or go to Torry's or one of those places listed down the bottom of Help | Delphi Direct. Have a look through for a custom TEdit replacement control that has what you need. Try to get one free with source. But for me, editing text in a right-aligned box would feel weird. -- Doug Burbidge mailto:dougburbidge@yahoo.com
 
I am really sorry for confusing you guys. I had oneline TMemo and i was looking at it's properties.

--- markus
 
thanx the memo pad idea woks
im making a calculator program so thats why i need the right alignment but otherwise it would feel weird.

thanx again
~azteroth~
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top