measuring a string using .net

Here’s how you get the width and height of a string using the .NET framework ( the example is for IronPython, but you can easily adjust this for any CLI language ) :

size = System.Windows.Forms.TextRenderer.MeasureText("measure this",font)
print size.Width
print size.Height

note that font must be the font you’re using to draw the string.


0 Responses to “measuring a string using .net”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog Stats

  • 237,011 hits

%d bloggers like this: