Board index » delphi » Align text in TEdit

Align text in TEdit

Hello

Is there a way to align text in an TEdit component. I would like to have
the text inside to be aligned to the right side, and not to the left as
default.

Hope someone can help me. Thanks in advance.

J?rn Walle
Norway

 

Re:Align text in TEdit


Quote
J=F8rn Walle wrote:
> Is there a way to align text in an TEdit component. I would like to hav=
e
> the text inside to be aligned to the right side, and not to the left as=
> default.

If you can use a Panel (in place of the Edit), you can just set the
align property.

Aage J.
01

Re:Align text in TEdit


Actually, I think you mean the Alignment property.

Ken
--------------------------------------
Notice at no time do my fingers leave my hands...
This Internet thing...  it's a fad!  ;-)
--------------------------------------
Master Certified Delphi 3 Instructor
Master Certified C++Builder Instructor
http://www.knowledgeable.com
k...@knowledgeable.com
+

Torolf Holte <hol...@sn.no> wrote in article <336EE061.3...@sn.no>...

Quote
J?rn Walle wrote:
> Is there a way to align text in an TEdit component. I would like to have
> the text inside to be aligned to the right side, and not to the left as
> default.

If you can use a Panel (in place of the Edit), you can just set the
align property.

Aage J.
01

----------

Re:Align text in TEdit


There is a Delphi component named UALNEDIT found in Delphi Super Page. It's
from gmo...@rgn.it

Re:Align text in TEdit


Quote
 J?rn Walle wrote:
> Is there a way to align text in an TEdit component. I would like to have
> the text inside to be aligned to the right side, and not to the left as
> default.

Torolf Holte wrote

-If you can use a Panel (in place of the Edit), you can just set the
-align property.

I think the original post meant justification not alignment, anyway the
quick way to achieve this rather than a convoluted rewrite of Tedit is to
use a singe line memo component with wordwrap off. Tmemo supports
justification.

David.

Re:Align text in TEdit


Quote
>> J?rn Walle wrote:
>> Is there a way to align text in an TEdit component. I would like to have
>> the text inside to be aligned to the right side, and not to the left as
>> default.

> If you can use a Panel (in place of the Edit), you can just set the
> align property.

> Aage J.
> 01

> ----------All these "solutions" are not very OO-like. A couple of weeks ago I found the

following lines of code in a newsgroup ... and it works! (Sorry, that I did not
keep the name of the author).

[Start Quotation]
Basically in the CreateParams procedure, I add ES_RIGHT and ES_MULTILINE to the
style.  I add ES_MULTILINE because ES_RIGHT doesn't work without it.  This,
however makes the control allow multiline entry, so I filter the key presses.  The
class looks like this:

  type
    TRightEdit :class(TEdit)
      protected
        procedure CreateParams( var Params :TCreateParams ); override;
        procedure KeyPress( var Key :Char); override;
    end;

  procedure TRightEdit.CreateParams( var Params :TCreateParams );
  begin
    inherited CreateParams(Params);
    Params.Style := Params.Style or ES_RIGHT;
    Params.Style := Params.Style or ES_MULTILINE;
  end;

  procedure TRightEdit.KeyPress( var Key :Char);
  begin
    if Key in [ #10, #13 ] then
      Key := #0
    else
      inherited KeyPress(Key);
  end;

[End Quotation]
... and it's also true that ES_RIGHT does not work without ES_MULTILINE (a bug or
a feature?).
HTH
Albert
------------------------------------------------------------------
albert.ga...@mch.sni.de  <all postings reflect my private opinion>  
Jetzt auch im Muenchner Buergernetz:     albert.ga...@muenchen.org

Re:Align text in TEdit


Using the TMemo will work and allow you to set the Alignment property to
taLeftJustify but you'll also want to prevent the Return key from kicking
you to the next line in the TMemo which would be confusing.  You can do
this using the Memo's OnKeyPress event to kill the Return key.  Something
like:

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then  { if it's a return key}
    Key := #0;         { kill the key stroke}
end;

Hope this helps!
--
Rod Geraghty (:>)
GERA-Tech
Ottawa, Canada
gera...@ibm.net

David F. <dfab...@eastcoast.net.au> wrote in article
<5knamg$m2...@auwa0.connect.com.au>...

Quote

>  J?rn Walle wrote:

> > Is there a way to align text in an TEdit component. I would like to
have
> > the text inside to be aligned to the right side, and not to the left as
> > default.
> Torolf Holte wrote

> -If you can use a Panel (in place of the Edit), you can just set the
> -align property.

> I think the original post meant justification not alignment, anyway the
> quick way to achieve this rather than a convoluted rewrite of Tedit is to
> use a singe line memo component with wordwrap off. Tmemo supports
> justification.

> David.

Other Threads