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

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
 
B

bchildsdotcom

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top