Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Alignment with TEdit (Right Justify)

Posted on 2001-08-17
7
Medium Priority
?
4,793 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 17

Accepted Solution

by:
inthe earned 150 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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

688 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