Solved

Alignment with TEdit (Right Justify)

Posted on 2001-08-17
7
4,054 Views
Last Modified: 2007-12-19
How can I change the alignment of a text in TEdit? There is no property like alignment, but I want to set the alignment to "taRightJustify" like in TMemo.
0
Comment
Question by:rothst
7 Comments
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
A couple of options.

1 - Use another component (TMS's AdvEdit - www.tmssoftware.com)
2 - Use a memo and fix it so it looks like an edit box.
3 - Subclass the TEdit and add an Align property.
4 - Add spaces to the front of the text so that it right aligns. (Very poor way, but may actually be the quickest to write!).

Regards,

Richard Quadling.
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
try

  Edit1.BiDiMode := bdRightToLeft;


but's not too perfect
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
>3 - Subclass the TEdit and add an Align property.

this is the way, but this is not enough, you must also overwrite the
createparams procedure to set the choosen alignment

meikl ;-)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
Comment Utility
try installing this:


unit AlignEdit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type
  TEditAlign = class(TEdit)
  private
    { Private declarations }
  f_alignment: TAlignment;
  protected
    { Protected declarations }
    procedure CreateParams(var params:TCreateParams); override;
  procedure SetAlignment(value: TAlignment);
 public
    { Public declarations }
constructor Create(AOwner: TComponent); override;
  published
    { Published declarations }
 property Alignment:TAlignment read f_alignment write SetAlignment;
 
  end;

procedure Register;

implementation
constructor TEditAlign.Create(AOwner: TComponent);
begin
  inherited create(AOwner);
  end;

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

procedure TEditAlign.CreateParams(var params:TCreateParams);
const
    Alignments : array[TAlignment] of Longint = (ES_LEFT, ES_RIGHT, ES_CENTER);
begin
 inherited CreateParams(Params);
 Params.Style := Params.Style or Alignments[f_Alignment] or ES_MULTILINE;
  end;
procedure Register;
begin
  RegisterComponents('Samples', [TEditAlign]);
end;

end.
0
 

Author Comment

by:rothst
Comment Utility
So, there is no way without creating a new component. I would prefer to use the existing TEdit component.
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
i think a talignedit is the only correct way ,any other way would probably be messy/unstable and merely  a "workaround".
note,
 any other time you need a extra feature not provided by standard tedit you can add any extra code needed to this new tedit so to have a custom tedit with all your extra features in ,like you may want to do some events on mouseenter/leave etc..
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
I have to agree with inthe on the subclassing. Though it was the third my the list, it is not until recently have I got to grips with actually doing this.

You are still using the standard component, but you are adding a little to it. This is exactly the reason why you this option. Instead of starting from scratch and doing everything, you simply add the bit you want.

Regards,

Richard Quadling.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now