Solved

Alignment with TEdit (Right Justify)

Posted on 2001-08-17
7
4,619 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month6 days, 8 hours left to enroll

636 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