PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms Autosize Textbox or RichTextBox

Reply

Autosize Textbox or RichTextBox

 
Thread Tools Rate Thread
Old 14-12-2005, 05:42 PM   #1
=?Utf-8?B?QnJld3NraQ==?=
Guest
 
Posts: n/a
Default Autosize Textbox or RichTextBox


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.
  Reply With Quote
Old 14-12-2005, 08:54 PM   #2
Peter Oliphant
Guest
 
Posts: n/a
Default Re: Autosize Textbox or RichTextBox

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.



  Reply With Quote
Old 15-12-2005, 12:25 AM   #3
=?Utf-8?B?QnJld3NraQ==?=
Guest
 
Posts: n/a
Default Re: Autosize Textbox or RichTextBox

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.

>
>
>

  Reply With Quote
Old 15-12-2005, 04:31 PM   #4
=?Utf-8?B?VG9kZCBCcmV3ZXI=?=
Guest
 
Posts: n/a
Default RE: Autosize Textbox or RichTextBox

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.

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off