?
Solved

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

Posted on 2003-10-22
5
Medium Priority
?
158 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
[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
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 23

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 75 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

Technology Partners: 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!

Question has a verified solution.

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

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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
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

765 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