MeasureString(string s,Font font) dosen't return right pixels

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The function return quite rough pixels.

e.g. if you use Font: Verdana, Font style:Regular, Size:8 and type 60 upper
case
character C, the functuion returns pixels 478.3639, but actualy it occupies
a textbox
that has width 545 pixels, that is about 13% difference. When using the
function to
get pixels and grow a textBox, the textBox is not big enough to show all
characters.

For other characters like lower case i, it return more pixels than it it has.

So it is impossile to use the function to get pixels to expand or shink a
textbox
dynamically when typing character.

Is there any other way?

Thanks
 
The measure string method only returns the size of the string when
using the drawString method... Since a textbox has a border etc, the
size of the text box will be larger than just the size of the string.

Have you tried using the AutoSize property of the text box?

-Ben Childs
 
Back
Top