简体   繁体   中英

How to get width and height of string on the screen?

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?

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 .

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:

third font in font family is significantly larger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM