?
Solved

Set memo1.height according to content (lines.count) problem

Posted on 2003-03-21
3
Medium Priority
?
246 Views
Last Modified: 2010-04-04
I have form1 set to autosize.  I want memo1 to resize (height only) according to how many lines are in it without having to use ssvertical.
In other words, when memo1 loads up (from text in a text file), if it has more that what will fit on the screen, I need to resize it accordingly so when I print form1, it will print all text on form and memo1.

In my code, I hide the buttons on the form before it prints then switch them back on.

I've tried // memo1.height := memo1.lines.count * 20;
but that doesn't work quite right.  It does resize it but not right.  My font is Tahoma 10 regular.

Thanks

Mark
0
Comment
Question by:Mark Brady
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
emadat earned 150 total points
ID: 8184150
Try this:

//=========================================================
memo1.Height := memo1.Lines.Count * canvas.TextHeight('a') + 10;
//=========================================================

You can experiment with the value 10 to find the value tha best suit you.

Aslo you can do the following:
//=========================================================
iMemoHeight := memo1.Lines.Count * canvas.TextHeight('a')+ 10;
if iMemoHeight> iMyMaximamu then iMemoHeight := iMyMaximamu;
memo1.Height := iMemoHeight;
//=========================================================
where iMyMaximamu is the maximum height for the memo.
0
 
LVL 3

Expert Comment

by:LukA_YJK
ID: 8186625
I remember in Richedit there is an Event OnRequestResize, maybe it would be a more stable solution?
0
 
LVL 20

Author Comment

by:Mark Brady
ID: 8187619
I've used your answer and modified it a little.  This is what I have now that works for me.

procedure TForm1.Button1Click(Sender: TObject);
begin
if button1.caption = 'Add Data' then
begin
button1.caption := 'Clear';
memo1.lines.loadfromfile ('c:\bonusplus\data\Mytext.txt');
memo1.Height := (memo1.Lines.Count + 1) * canvas.TextHeight('a') + 10;

end
else
begin
button1.caption := 'Add Data';
memo1.clear;
memo1.Height := (memo1.Lines.Count + 1) * canvas.TextHeight('a') + 10;
end;
if memo1.height > 490 then begin
memo1.height := 490;
memo1.ScrollBars := ssvertical;
end
else
memo1.ScrollBars := ssnone;
end;


end.


I had to add the '+ 1' so it would show every line in the memo but in any case, the problem is solved, thank you.

Mark
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question