Autofit WinForms RichTextBox to its contents

mrtaikandi picture mrtaikandi · Apr 9, 2009 · Viewed 15.5k times · Source

Does anybody know how can I dynamically resize a RichTextBox control to its contents?

Answer

dardo picture dardo · May 17, 2013

I guess I am far too late but take a look at this

It's just two code lines:

private void rtb_ContentsResized(object sender, ContentsResizedEventArgs e)
{
    ((RichTextBox)sender).Height = e.NewRectangle.Height + 5;
}