Solved

Alignment with TEdit (Right Justify)

Posted on 2001-08-17
7
4,441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 6396376
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:Mohammed Nasman
ID: 6396637
try

  Edit1.BiDiMode := bdRightToLeft;


but's not too perfect
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6398473
>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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6399576
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
ID: 6405242
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
ID: 6405374
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:Richard Quadling
ID: 6405529
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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