Measure Character
-
-
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.
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
-
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.
You should also make sure that the
StringFormat
you're using has theStringFormatFlags.MeasureTrailingSpaces
excluded.Microsoft MVP, Visual C# My Articles
-
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
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.