Solved

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

Posted on 2003-10-22
5
157 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 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

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

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…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
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…

707 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