Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto-adjusting font size

Status
Not open for further replies.

jjschwartz

Technical User
Feb 3, 2004
23
US
I am displaying various text in a statictext box. I don't want to use scroll bars or have it user-adjustable in any way.

Sometimes the text is too much to fit into the statictext box. When this happens I would like to shrink the fontsize.

I have no trouble adjusting the fontsize (I'm a relative newbie but I can do that). It's figuring out *when* the text is too much and the font needs to be changed that I'm having trouble with. Counting characters or words isn't reliable.

I need to determine when a window *would* add scroll bars if it had them to display the text. That seems the best way to decide if not all the text is being displayed. Any suggestions?

Thanks in advance.

Jeff Schwartz
 
The canvas have some methods for text size calculation (GetTextWidth if memory serves).

IMO, the best way is calculating your text width, checking if it fits in the text area and proceeding acordingly.

buho (A).

 
Thanks for the lead.

I'm not sure how to determine if my text fits.

As far as I can tell, a statictext (or a TLabel or a TEdit) doesn't have a canvas property.

Also, this is multi-line text so I'm thinking I might have calculations I need to do to deal with the headers and footers and line spacing.

Delphi knows when the text is too big to fit; why can't I :) ?

Jeff Schwartz
 
The fact of the controls not having a canvas don't matter, use the form canvas to measure the sizes.

For multiline texts, take a look at DrawText in the SDK. Call it with
uFormat = DT_EXPANDTABS or DT_CALCRECT or DT_WORDBREAK
to have Win calculating the needed area.

buho (A).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top