Click to See Complete Forum and Search --> : Confusing Graphics.MeasureString returns


venAdder
February 22nd, 2006, 04:00 PM
Hi,

I am confused by some values returned by graphics.MeasureString method
g.MeasureString(Convert.ToString(sb), PrintFont).Width is following:

g-valid graphics object, PrintFont is constant for both calls and value of Convert.ToString(sb) is as follows

" Item "

width returned is 177.soemthingsomething

" Item l"
width returned is 333.something.

How does adding one extra character make such a huge difference?
Also if i add this extra character the string is printed what it should be printed as, but if I omit l at the end all the trailing spaces are truncated and the string is printed!!!!!!!

What is going on over here?

Help will be highly appreciated. Thank You

venAdder
February 23rd, 2006, 11:20 AM
Oops the string dind't appear right in the post, the spaces got ommited. It is suppsed to be liek this

"23leadingspaces Item 23trailing spaces"

"23leadingspaces Item 23trailing spaces l"

Someoen help please.

DSJ
February 23rd, 2006, 12:59 PM
If your font is a proportional font, the leading spaces (and trailing spaces on your first item) will amount to nothing as they take no space to print.

venAdder
February 23rd, 2006, 08:19 PM
What's a propotional font and how do I tell?

thanks for reply.

DSJ
February 24th, 2006, 08:03 AM
In proportional fonts, each letter has it's own size, in non-proportional fonts, each letter is the same. An I for example is the same size as a W. In proportional, an I is much skinner than a W.

Gizmo001
February 24th, 2006, 11:20 AM
DSJ:

Could you give examples of oft-used proportional and non-proportional fonts. Thanks.

DSJ
February 24th, 2006, 11:35 AM
I think I have my descriptions reversed above. Courier is about the only fixed size font used anymore. Go into Word and choose Times new Roman and type spacebar spacebar spacebar 123456789 [Enter]. Now, change the font to Courier and type the same thing. You'll see what I'm talking about.

venAdder
February 27th, 2006, 12:04 PM
Okie i got teh meanign of propotional and np font, but it still dosn't explain the problem I have.

Am not using Courier font, infact am using one of the default fonts represented by
FontFamily.GenericSansSerif

But I willt ry changing to arial or even times new roman.

Thanks for help.