CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2004
    Posts
    391

    Confusing Graphics.MeasureString returns

    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

  2. #2
    Join Date
    Aug 2004
    Posts
    391

    Re: Confusing Graphics.MeasureString returns

    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.

  3. #3
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Confusing Graphics.MeasureString returns

    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.

  4. #4
    Join Date
    Aug 2004
    Posts
    391

    Re: Confusing Graphics.MeasureString returns

    What's a propotional font and how do I tell?

    thanks for reply.

  5. #5
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Confusing Graphics.MeasureString returns

    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.

  6. #6
    Join Date
    Dec 2002
    Posts
    305

    Re: Confusing Graphics.MeasureString returns

    DSJ:

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

  7. #7
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Confusing Graphics.MeasureString returns

    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.

  8. #8
    Join Date
    Aug 2004
    Posts
    391

    Re: Confusing Graphics.MeasureString returns

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured