G
Guest
Long ago I developed a simple algorithm for calculating how much space is
required to display a multi-line label in a limited width. It seemed to be
working okay but then my testing revealed a flaw when trying to display the
following string with an MS Sans Serif 8 point font in a 208 pixel width
space:
"A $50-million investment in cycling infrastructure - the largest history of
the province"
Using the Graphics "MeasureString" function it determined that 2 lines were
necessary to display this text. But unfortunately the longer words forced a
word-wrap sooner than usual. So the string ended up being displayed like
this:
A $50-million investment in cycling
infrastructure - the largest history of the
province
As you can see, this is 3 lines, not 2. I realize I could overcompensate
the height required but then this will add an excessive vertical margin in
many cases. So I'm wondering if anyone has come up with a superior, accurate
approach to this problem?
required to display a multi-line label in a limited width. It seemed to be
working okay but then my testing revealed a flaw when trying to display the
following string with an MS Sans Serif 8 point font in a 208 pixel width
space:
"A $50-million investment in cycling infrastructure - the largest history of
the province"
Using the Graphics "MeasureString" function it determined that 2 lines were
necessary to display this text. But unfortunately the longer words forced a
word-wrap sooner than usual. So the string ended up being displayed like
this:
A $50-million investment in cycling
infrastructure - the largest history of the
province
As you can see, this is 3 lines, not 2. I realize I could overcompensate
the height required but then this will add an excessive vertical margin in
many cases. So I'm wondering if anyone has come up with a superior, accurate
approach to this problem?