New to Telerik UI for WinForms? Download free 30-day trial

How to Measure Text

Environment

Product Version Product Author
2021.2.511 Telerik UI for WinForms Desislava Yordanova

Description

There are different approaches for measuring some text considering the font family and font size. That is why it is important to know first how the text is being rendered in order to measure it correctly.

Solution

By default, Telerik Presentation Framework uses GDI+ to measure and render the text. You can easily switch to GDI instead by setting the UseCompatibleTextRendering property to false for the respective control:

That is why when using GDI for rendering the text, it is suitable to use the TextRenderer.MeasureText method for measuring it. And for GDI+, feel free to use the Graphics.MeasureString method. Both methods offer different overloads allowing you to measure the text in a precise manner according to different criteria that you may have, e.g. format flags, font, available width, etc.

See Also

In this article
Not finding the help you need? Improve this article