It has been identified that a RichTextBox is a mixture of many different fonts,
font sizes, and typographical stylings. He would have to call MeasureString
for every combination that exists in his RichTextBox to get the actual size.
If the insistance is still there to use this control, then I'd have to recommend
two things. The first is to ensure that there aren't any newline characters. You
can't, for instance, grow your control to fit the string, if it wraps itself. If
it
doesn't wrap itself, then grow your control in response to GetLineFromCharIndex
where you pass in the index of the last character. If you are double slick, you
can
do the entire process in without resizing more than once...
int lines = rtb.GetLineFromCharIndex(lastChar);
Point p = rtb.GetPositionFromCharIndex(lastChar);
rtb.Width = rtb.Width * (lines - 1) + (p.X);
I wrapped p.X because I'm not sure what coordinate system it is measure in. You
may have to do some math to find out how far from the edge of the control it is
in
case the point is in screen coordinates. To take a shorcut, just use the:
rtb.Width = rtb.Width * lines;

Signature
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
> What about using the Graphics->MeasureString( String, Font ) method to capture
> the width required? Then use the returned size to set your RichTextBox up.
[quoted text clipped - 14 lines]
>> Thanks,
>> Marcin Waligora