tech_01

tech_01

  • NA
  • 1
  • 0

Rich Text Box Questions

Jun 7 2006 2:58 AM
I am working on an application with a rich text box and I am starting to go crazy.

Here’s what I need to do:

* Set the width of the text box to the width of the widest string.
* Get the height of the text box given a particular width so that all text fits in and there are no vertical or horizontal gaps (i.e. tightest configuration) and no scroll bars.
* Get the next narrowest/widest configuration of the text box which has one less or one more line.


I have tried using MeasureString (with GenericTypographic and GenericDefault), I have tried using SetMeasureableCharactersRanges, I have tried counting pixels, I have tried enabling anti-aliasing and smoothing text, I feel that I have tried everything.

Unfortunately it seems that when I measure strings and then use these measurements with the text box, they mismatch.

For example, my text measuring function tells me that the width of the longest word is 10. However, when I set the width of the text box to 10 it turns out to be too small.

To make it right I have to add a fudge factor. Unfortunately it seems that for different strings the amount that I need to add varies. Sometimes it can be 1, sometimes it can be 10.

I am aware of the issues between GDI and GDI+ but is there nothing one can do?

Any help/suggestions would be greatly appreciated.

Thanks.

Btw, I am using c#