views:

80

answers:

2

Lets say I've a string and some font (name, size, etc...).
How to get width and height, measured in pixels, of such string displayed on the screen?

+3  A: 

The easy answer is Graphics.MeasureString. But it's rather infamous for not being particularly accurate. If you need better accuracy you can check out this article: Using MeasureCharacterRanges to Draw Text.

danbystrom
eg. sucks with multiline
WooYek
+1  A: 

You didn't specify if you were using WinForms or ASP.NET.

If this is a web site, the answer I gave on this question can be easily distilled to a working solution for your question:

http://stackoverflow.com/questions/2118720/third-font-in-font-family-is-significantly-larger/2119438#2119438

richardtallent
I'm using WinForms, but Your answer might be helpful in the future, so thanks anyway.
Tomek Tarczynski