GraphicsPath.AddString using measurestring

false74

Well-known member
Joined
Aug 4, 2010
Messages
76
Programming Experience
Beginner
I'm drawing text using a graphicpath with the AddString method:

VB.NET:
        dim path = New GraphicsPath
        path.AddString(Me.Text, Me.Font.FontFamily, Me.Font.Style, Me.Font.Size, New Point(0, 0), Me.Format)

And I would like to measure the size of the drawn text.
Using the MeasureString method in the graphics class does not yield the correct size because GraphicPaths seems to draw the text larger or smaller than the normal Graphic.DrawString method would (I even tested using all the available GraphicUnits when creating the font).
Getting the bounds of the GraphicPath gets me the correct size but there is one big problem I have with this: When drawing text that has leading or trailing spaces or invisible characters (" abc" or "abc ") the bounds will ignore those spaces (since there is no path drawn for a space) but draw it correctly thus giving me an incorrect size.
" abc" = the same bounds as "abc" and so on.

How can I get the proper size of the drawn text including the spaces?
 
Back
Top