Solved

How to make the text in the Edit field 'Right justify'

Posted on 2003-10-22
5
152 Views
Last Modified: 2010-04-05
hello all,

             Normally the text in the edit field is 'leftjustified'. i want to make it Right justify, for that which property i must change?

thanks
pvp
0
Comment
Question by:pvp1
5 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9597889
usually not possible the standard TEdit,
but you can descand and expand the TEdit like
this one i found in my paq

------------
from barry (inthe)




                     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.

-----------------

sorry about the bad paste

meikl ;-)

0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 9598049
or you can use this code found at http://www.undu.com/Articles/000207c.html

to right justify a TEdit...

procedure RJustifyEdit(var ThisEdit : TEdit);
var
 Left, Width : Integer;
 GString : String;
 Rgn : TRect;
 TheCanvas : TControlCanvas;
begin
  TheCanvas := TControlCanvas.Create;
  try
    TheCanvas.Control := ThisEdit;
    GString := ThisEdit.Text;
    Rgn     := ThisEdit.ClientRect;
    TheCanvas.FillRect(Rgn);
    Width   := TheCanvas.TextWidth(GString);
    Left := Rgn.Right - Width - 1;
    TheCanvas.TextRect(Rgn, Left, 0, GString);
  finally
    TheCanvas.Free;
  end ;
end;
0
 
LVL 5

Accepted Solution

by:
Hypoviax earned 25 total points
ID: 9667580
You shouldn't need all this code. From the top of my head just change the align or alignment property.
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9732080
pvp1:

You should stay active in your questions.
You're asking another, but have not responded to the suggestions here.
The more you stay active in your questions (which shows that you care), the more the experts will care too.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10207937
usual a TEdit has no alignment-property,

the accepted answer is only applyable for TMemo and TRichedit.

if the question was pointed to TMemo or TRichedit,
then the question was unclear.

meikl ;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

14 Experts available now in Live!

Get 1:1 Help Now