views:

139

answers:

1

This is the inverse of Determine Label Size based upon amount of text and font size in Winforms/C#.

Given a rectangle of fixed height but variable width, is there an efficient way to determine the largest size of a given font that will fit in the rectangle (height-wise) without risk of losing ascenders/descenders?

I'm currently considering iterative use of MeasureString() to find the best font size but wonder if there's a better way.

+1  A: 

I've never found a better way to do it than using MeasureString iteratively. You can optimise by jumping in increments.

WPF has some nicer text sizing options, though it feels like rubbing salt in the wound.

TreeUK
I went with this and it works well enough. Yeah, too bad the target audience is very slow to update .NET versions...
Eric J.