Problem making memo grow with lines of text.
Hi.
I am trying to make the memo control grow and shrink with the width
and # of lines of text entered. I'm doing ok so far with the width
but the height is another story.
When I press enter after entering text on the first line of the memo
the line of text scrolls up out of site and the memo remains single
line height.
What I want is that the memo should increase in size by the font
height * 1. I want the first line of text to allways remain visible
at the top of the memo.
If I have not explained the problem well enough here is the code.
var
I, CurMaxWidth, CurMaxHeight, LineCount, CurHeight : Integer;
procedure TForm1.FormCreate(Sender: TObject);
begin
Memo1.Lines.Clear;
CurMaxWidth := 0;
CurMaxHeight := 0;
CurHeight := 0;
LineCount := Memo1.Lines.Count;
end;
procedure TForm1.Memo1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
CurMaxWidth := 0;
for I := 0 to Memo1.Lines.Count do
if Canvas.TextWidth(Memo1.Lines.Strings[I]) > CurMaxWidth then
CurMaxWidth := Canvas.TextWidth(Memo1.Lines.Strings[I]);
if Memo1.Lines.Count < 1 then
CurMaxHeight := 1
Else
CurMaxHeight := Memo1.Lines.Count;
Memo1.Width := CurMaxWidth + Canvas.TextWidth('W');
Memo1.Height := CurMaxHeight * Canvas.TextHeight('y');
end;
procedure TForm1.Memo1Enter(Sender: TObject);
begin
if Memo1.Lines.Count < 1 then
CurMaxHeight := 1
Else
CurMaxHeight := Memo1.Lines.Count;
Memo1.Width := CurMaxWidth + Canvas.TextWidth('W');
Memo1.Height := CurMaxHeight * Canvas.TextHeight('y');
end;
TIA
Darin