PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Autosize Textbox or RichTextBox
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Autosize Textbox or RichTextBox
![]() |
Autosize Textbox or RichTextBox |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
I have a need to have a Textbox or RTF box autosize to content. In other
words, as the user types, the textbox grows vertically to show all the lines rather than show scrollbars. I was under the impression that this ability was going to be added in VS2005, but it certainly isn't obvious to me. Any ideas on how to accomplish this would be appreciated. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
I think studying these should do the trick:
http://msdn2.microsoft.com/en-us/li...e.autosize.aspx http://msdn2.microsoft.com/en-us/li....multiline.aspx [==P==] "Brewski" <Brewski@discussions.microsoft.com> wrote in message news:97684248-6C37-4A01-B06F-069B06D63DAE@microsoft.com... >I have a need to have a Textbox or RTF box autosize to content. In other > words, as the user types, the textbox grows vertically to show all the > lines > rather than show scrollbars. > > I was under the impression that this ability was going to be added in > VS2005, but it certainly isn't obvious to me. > > Any ideas on how to accomplish this would be appreciated. |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Multiline does allow the user to type multiple lines of text. Autosize,
however, only changes the control size when the font changes, and on both the RichTextBox and TextBox it says "This property is not relevant to this class." I need the control to size vertically as the user enters text at runtime. Todd "Peter Oliphant" wrote: > I think studying these should do the trick: > > http://msdn2.microsoft.com/en-us/li...e.autosize.aspx > http://msdn2.microsoft.com/en-us/li....multiline.aspx > > [==P==] > > "Brewski" <Brewski@discussions.microsoft.com> wrote in message > news:97684248-6C37-4A01-B06F-069B06D63DAE@microsoft.com... > >I have a need to have a Textbox or RTF box autosize to content. In other > > words, as the user types, the textbox grows vertically to show all the > > lines > > rather than show scrollbars. > > > > I was under the impression that this ability was going to be added in > > VS2005, but it certainly isn't obvious to me. > > > > Any ideas on how to accomplish this would be appreciated. > > > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
OK, I finally figured out the answer. The key is handling the
ContentsResized event on the RichTextBox (doesn't exist on a TextBox). The ContentsResizedEventArgs has a NewRectangle property which will give you the desired size. Here is what I have: private void rtb_ContentsResized(object sender. ContentsResizedEventArgs e) { (RichTextBox)sender.Height = e.NewRectangle.Height + 5; } So, there is the solution if anyone ever wants to know. Brewski AKA Todd Brewer. "Brewski" wrote: > I have a need to have a Textbox or RTF box autosize to content. In other > words, as the user types, the textbox grows vertically to show all the lines > rather than show scrollbars. > > I was under the impression that this ability was going to be added in > VS2005, but it certainly isn't obvious to me. > > Any ideas on how to accomplish this would be appreciated. |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

