Re: Delphi TEdit-alignment

By webmaster Guido on September 25, 2001

In Reply to: tedit-alignment posted by p12114 abobby on September 25, 2001

: How can I align the text(left or right)inside a tedit box?

The text of a TEdit is always left aligned, you can't change that.
But here's a trick: use a TMemo instead of a TEdit, because you can change its alignment in the Object Inspector (left-justify, center, right-justify). If you want it to behave like a TEdit, you have to limit its maximum number of lines to 1, like this:

- set WantReturns to FALSE (no end-of-lines can be entered by pressing ENTER);
- set WantTabs to FALSE (no tabs can be entered by pressing TAB);
- if desired, set MaxLength to a reasonable number, e.g. 25 or 50 or whatever you expect as a maximum length. This last step is not really necessary, but limiting the length of a single-line inputbox (even of a 'normal' TEdit) is less confusing for the user. Moreover, it might protect you program from silly things, such as a user trying to copy a text of a few hundred kilobytes into the inputbox ;-)

Related Articles and Replies

[ DelphiLand FAQ ] [ Delphi Tutorials ]