Solved

Alignment with TEdit (Right Justify)

Posted on 2001-08-17
7
4,304 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: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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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