Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to adjust a memo to the height required to show all text without scrollbars Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
12-Oct-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
125
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How would I find out how many viewed lines are in a memo? For example, if one line 
is wrapped once, it would count as two. I need to stretch it so that all lines are 
visible.

Answer:

Solve 1:

Adjusting a memo to the height required to show all text without scrollbars:

1   procedure TForm1.Button2Click(Sender: TObject);
2   var
3     rect1, rect2: TRect;
4     S: string;
5   begin
6     s := Memo1.Text;
7     memo1.Perform(EM_GETRECT, 0, longint(@rect1));
8     rect2 := rect1;
9     canvas.font := memo1.font;
10    DrawTextEx(canvas.handle, Pchar(S), Length(S), rect2, DT_CALCRECT or
11      DT_EDITCONTROL or DT_WORDBREAK or DT_NOPREFIX, nil);
12    memo1.Height := memo1.height + rect2.bottom - rect1.bottom;
13  end;



Solve 2:

I use the following:

14  with TControlCanvas.Create do
15  try
16    Control := MmoView;
17    Font.Assign(MmoView.Font);
18    FFontHeight := TextHeight('Q');
19    FFontWidth :=
20      TextWidth('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') div 52;
21  finally
22    Free;
23  end;
24  
25  FMaxBuf := (MmoView.ClientHeight div FFontHeight) * (MmoView.ClientWidth div
26    FFontWidth);
27  FMaxLines := (MmoView.ClientHeight div FFontHeight) - 1;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC