Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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