Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Graphics.MeasureString accuracy

Graphics.MeasureString accuracy

Scheduled Pinned Locked Moved C#
comgraphicsquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tasoss
    wrote on last edited by
    #1

    Hello. I'm using

    Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
    (int)gr.MeasureString(xrt.Rows[x].Cells[y].Text, xrt.Rows[x].Cells[y].Font).Width;

    But as you can see http://img156.yfrog.com/img156/3585/measurestring.jpg it doesn't work as i would like. Can you please advice me so i can increase its accuracy? Thank you in advance!

    C L 2 Replies Last reply
    0
    • T tasoss

      Hello. I'm using

      Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
      (int)gr.MeasureString(xrt.Rows[x].Cells[y].Text, xrt.Rows[x].Cells[y].Font).Width;

      But as you can see http://img156.yfrog.com/img156/3585/measurestring.jpg it doesn't work as i would like. Can you please advice me so i can increase its accuracy? Thank you in advance!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      What's wrong with it ? Also, you can't make it more accurate than it is. I am sure it is accurate, it always has been for me.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      T 1 Reply Last reply
      0
      • T tasoss

        Hello. I'm using

        Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
        (int)gr.MeasureString(xrt.Rows[x].Cells[y].Text, xrt.Rows[x].Cells[y].Font).Width;

        But as you can see http://img156.yfrog.com/img156/3585/measurestring.jpg it doesn't work as i would like. Can you please advice me so i can increase its accuracy? Thank you in advance!

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, I've read before there are some slight inaccuracies, so I tend to add some 10 pixels to make strings fit. This article will tell you more: Bypass Graphics.MeasureString limitations[^] :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        1 Reply Last reply
        0
        • C Christian Graus

          What's wrong with it ? Also, you can't make it more accurate than it is. I am sure it is accurate, it always has been for me.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          T Offline
          T Offline
          tasoss
          wrote on last edited by
          #4

          Hello and thanks for replying. Well "personal information" is not in the same line.Moreover "Orders table" "for each order" etc. I would like them to be in the same line and not wordwraped.

          C 1 Reply Last reply
          0
          • T tasoss

            Hello and thanks for replying. Well "personal information" is not in the same line.Moreover "Orders table" "for each order" etc. I would like them to be in the same line and not wordwraped.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            Every time it wraps, it's because there's not enough room to fit them. If the column has been sized to the biggest string ( you don't actually tell us what you do with it ), then perhaps you just need to add a few pixels ?

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            T 1 Reply Last reply
            0
            • C Christian Graus

              Every time it wraps, it's because there's not enough room to fit them. If the column has been sized to the biggest string ( you don't actually tell us what you do with it ), then perhaps you just need to add a few pixels ?

              Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

              T Offline
              T Offline
              tasoss
              wrote on last edited by
              #6

              Thanks for the replies.Well i just want to fit the text exactly inside the cells(table cells).I create a table(control provided) and set text inside its cells.Then i process all the cells and try to set the correct width(using measurestring). How will i know that more pixels are needed to be added? I will try the links provided but i don't know if they fit in my occasion. Thanks again people.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups