0

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?

Denis Biondic
  • 7,943
  • 5
  • 48
  • 79

1 Answers1

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

Community
  • 1
  • 1
Xcelled
  • 2,084
  • 3
  • 22
  • 40