Solved

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

Posted on 2003-10-22
5
151 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

8 Experts available now in Live!

Get 1:1 Help Now