Board index » delphi » Right Align Text in TEdit

Right Align Text in TEdit

I was curious to know if there was a way to right align text in a TEdit
field?  Thanks in advance for any information!
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  mail to : mre...@ici.net                      
  WWW: http://www.ici.net/cust_pages/mrealm/BANDP.HTM
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
' It is better to die on your feet, than to live on your knees! '

 

Re:Right Align Text in TEdit


 Hi.

Yes there is a way, but you need to implement your own paint methods.
Look for TDBEdit in the source code for implementation of this feature.

Regards
Stig Johansen
DATAgruppen Danmark A/S

BP wrote in article <01bccb2d$8e06abe0$1a0ab...@mrealm.ici.net>...

Quote
>I was curious to know if there was a way to right align text in a TEdit
>field?  Thanks in advance for any information!
>--
>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>  mail to : mre...@ici.net
>  WWW: http://www.ici.net/cust_pages/mrealm/BANDP.HTM
>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>' It is better to die on your feet, than to live on your knees! '

Re:Right Align Text in TEdit


How about visiting Delphi Super Page?  You should find there at least
couple of enhanced TEdits with sources.

Quote

> >I was curious to know if there was a way to right align text in a TEdit
> >field?  Thanks in advance for any information!
> >--

Re:Right Align Text in TEdit


Quote
BP <mre...@ici.net> wrote:
> I was curious to know if there was a way to right align text in a TEdit
> field?  Thanks in advance for any information!

Below is a (untested) simple component which adds a Alignment property to
the standard edit component. To include it into your Delphi you only need to
add the unit headers and a registers procedure.

TAlignEdit=class(TEdit)
protected
  f_alignment: TAlignment;
  procedure CreateParams(var params:TCreateParams); override;
  procedure SetAlignment(value: TAlignment);
public
  constructor Create(AOwner: TComponent); override;
  property Alignment read f_alignment write SetAlignment default alLeft;
  end;

constructor TAlignEdit.Create(AOwner: TComponent);
begin
  inherited create(AOwner);
  f_alignment:=alLeft;
  end;

procedure TAlignEdit.SetAlignment(value: TAlignment);
begin
  if value<>f_alignment then begin
    f_alignment:=value;
    recreatewnd;
    end;
  end;

procedure TAlignEdit.CreateParams(var params:TCreateParams);
const
  Alignments: array[TAlignment] of longint = (es_left, es_right, es_center);
begin
  inherited CreateParams;
  params:=params or Alignments[f_alignment];
  end;

--
----------------------------------------------------------------------------
Andreas H"orstemeier                       | ..Our continuing mission:
email: a...@scp.de                           | to seek out knowledge of C,
       a...@farpoint.westend.de            | to explore strange unix
www:   http://www.westend.de/~hoerstemeier | commands, and to boldly code
fido:  2:2452/108                          | where no one has man page 4.
----------------------------------------------------------------------------  

Re:Right Align Text in TEdit


In article <01bccb2d$8e06abe0$1a0ab...@mrealm.ici.net>,
   "BP" <mre...@ici.net> wrote:
]-I was curious to know if there was a way to right align text in a TEdit
]-field?  Thanks in advance for any information!

here's an ancient post from this group that may help you...

Mark Vaughan

----

     Date[ 04/15/1996
   Author[ Ritchie Annand
  Address[ t...@netway.ab.ca
  Subject[ Right-justify TEdit Text
 Keywords[ TEdit, component, right-justify

 Question[
This below was passed on to me by Bill Hardey, who got it from someone else:

Quote
>    Below is a unit that someone sent to me about a week ago. It seems to
>work OK. I am not exactly sure how. I have not had time to study it.
>    The person who sent it to me had the following comment: "Here is a
>minimum component (lots of room for improvement) that handles text alignment
>in a TEdit."

Whoever the author is, that's where the credit is due.

  --=- Ritchie A.
          ]

 Response[
interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, menus;

type
  TEditAlignment = (eaLeft, eaCenter, eaRight);
  TAlignEdit = class(TCustomEdit)
  private
    { Private declarations }
    fAlignment: TEditAlignment;
    procedure setAlignment(nValue: TEditAlignment);
  protected
    { Protected declarations }
    procedure CreateParams(var Params: TCreateParams); override;
  public
    { Public declarations }
  published
    { Published declarations }
    property Alignment: TEditAlignment read fAlignment write
setAlignment;
    property AutoSelect;
    property AutoSize;
    property BorderStyle;
    property CharCase;
    property Color;
    property Ctl3D;
    property DragCursor;
    property DragMode;
    property Enabled;
    property Font;
    property HideSelection;
    property MaxLength;
    property OEMConvert;
    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 OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Custom', [TAlignEdit]);
end;

procedure TAlignEdit.setAlignment(nValue: TEditAlignment);
begin
  if fAlignment <> nValue then begin
    fAlignment:= nValue;
    RecreateWnd;
  end;
end;

procedure TAlignEdit.CreateParams(var Params: TCreateParams);
const
  Alignments: array[TEditAlignment] of Longint = (ES_LEFT, ES_CENTER,
ES_RIGHT);
begin
  inherited CreateParams(Params);
  CreateSubClass(Params, 'EDIT');
  Params.Style := Params.Style or ES_MULTILINE or Alignments[fAlignment];
end;

          ]

Other Threads