| |
 |
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;
|
|
| Hits/month |
2,500,000+ |
Downloads (Since May 2000) |
7,393,709 |
| Total Files |
6,023 |
| Forum msgs |
7,670 |
| Articles/FAQs |
70+/900+ |
Top Selling Software at Amazon
|