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. Measure Character

Measure Character

Scheduled Pinned Locked Moved C#
graphicstutorialquestion
4 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.
  • W Offline
    W Offline
    Werdna
    wrote on last edited by
    #1

    Is there a way to measure single character? Graphics.MeasureString seems to be off. For example if I have character "i", and the particular font I'm using it's one pixel wide, I'd like to know that it's 1 pixel wide. MeasureString adds some extra space.

    J H 2 Replies Last reply
    0
    • W Werdna

      Is there a way to measure single character? Graphics.MeasureString seems to be off. For example if I have character "i", and the particular font I'm using it's one pixel wide, I'd like to know that it's 1 pixel wide. MeasureString adds some extra space.

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Look at the System.Drawing.Graphics.MeasureCharacterRanges method, it should be all you need. Be forewarned: that method won't measure more than 32 characters. Call it recursively if you need to measure more than 32 characters. --------------------------- He who knows that enough is enough will always have enough. -Lao Tsu

      W 1 Reply Last reply
      0
      • W Werdna

        Is there a way to measure single character? Graphics.MeasureString seems to be off. For example if I have character "i", and the particular font I'm using it's one pixel wide, I'd like to know that it's 1 pixel wide. MeasureString adds some extra space.

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        You should also make sure that the StringFormat you're using has the StringFormatFlags.MeasureTrailingSpaces excluded.

        Microsoft MVP, Visual C# My Articles

        1 Reply Last reply
        0
        • J Judah Gabriel Himango

          Look at the System.Drawing.Graphics.MeasureCharacterRanges method, it should be all you need. Be forewarned: that method won't measure more than 32 characters. Call it recursively if you need to measure more than 32 characters. --------------------------- He who knows that enough is enough will always have enough. -Lao Tsu

          W Offline
          W Offline
          Werdna
          wrote on last edited by
          #4

          MeasureCharacterRanges makes things even worse. What i'm doing is drawing text on a curve, so I need to draw each character seperately, because each character is at different x, y position and different rotation angle. The way measurestring (or measurecharacterranges) work is that it looks like it's done using fixed width font.

          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