Max. # of chars on a single line of a multiline textbox

michael_hk

Centurion
Joined
Nov 24, 2003
Messages
199
Location
Hong Kong
Hi guys,

I have a resizable multiline textbox. How can I get the number of characters a single line can accommodate? I can only find textbox.Width...

Thanks.

Michael
 
Yes, the amount of chars will vary unless you use a font where the chars have a fixed width like courier new or lucida console, in which case you can use the Graphics.MeasureString() function to figure out how many chars you can fit.
 
Thanks for the info.

Finally I use "Courier New 9 pt" and estimate the # of chars by

nChar = textbox.Width / 10; // 10 pixel for a "Courier New 9 pt" letter

The result is not very accurate, but fine for me.

Thanks again for all your help.

Michael
 
Back
Top