Given a string with known formatting options, and a rectangle of known dimensions in pixels (widht, height), what is the best way to determine whether the string can fit for display in the given rectangle screen size of the current screen?
Asked
Active
Viewed 376 times
0
-
checkout http://stackoverflow.com/questions/263614/calculate-the-display-width-of-a-string-in-c – jamesSampica Jul 30 '13 at 17:31
1 Answers
2
Use Graphics.MeasureString. You'll need to either have a graphics object or create one, like this, for example.
MeasureString returns a Sizef
, which you can easily compare to your rectangle, which also has a Size property.
Edit: For WPF, you can also look into this: WPF equivalent to TextRenderer