Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Justifying edit text.


How can I create a single line edit control that is right or centered justified?   

    You can use a TMemo component, since the TEdit component does not directly support center and right justification. In addition, you will need to prevent the user from pressing the Enter, Ctrl-Enter, and a variety of arrow key combinations to prevent more than one line to be added to the memo. This can be accomplished by scanning the TMemo's text string for carriage return and line feed characters and deleting them during the TMemo's Change and KeyPress events. Optionally, you could replace any carriage returns with spaces to accommodate a multi-line paste operation. Example:

    procedure TForm .FormCreate(Sender: TObject);
    begin
      Memo .Alignment := taRightJustify;
      Memo .MaxLength := 24;
      Memo .WantReturns := false;
      Memo .WordWrap := false;
    end;
    procedure MultiLineMemoToSingleLine(Memo : TMemo);
    var
      t : string;
    begin
      t := Memo.Text;
      if Pos(# 3, t) > 0  then begin
        while Pos(# 3, t) > 0 do
         delete(t, Pos(# 3, t),  );
        while Pos(# 0, t) > 0 do
         delete(t, Pos(# 0, t),  );
        Memo.Text := t;
      end;
    end;
    procedure TForm .Memo Change(Sender: TObject);
    begin
      MultiLineMemoToSingleLine(Memo );
    end;
    procedure TForm .Memo KeyPress(Sender: TObject; var Key: Char);
    begin
      MultiLineMemoToSingleLine(Memo );
    end;
    

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use