Originally Posted by Rick Rothstein from http://www.codenewsgroups.net/group/microsoft.public.vb.general.discussion/topic10420.aspx
More than likely, this response will not be the one you use; but I'll post
it in case.<g>
The code below will allow you to set the maximum number of lines that a
TextBox can accept. If you want a non-multiline TextBox, simply set the
MaxLines variable to 1; if you want a multiline TextBox with 10 lines of
text maximum, set the MaxLines variable to 10. If you are showing
ScrollBars, they will "activate" if MaxLines is larger than the maximum
number of visible lines of text the TextBox can display.
So, you are probably asking, why might this not be what you want? Well, if
MaxLines is set to 1, then the maximum amount of text the user can type in
is limited to the width of the TextBox... no sideways scrolling of text for
the single line condition. Also, the ScrollBars that need to be displayed
for the multiline condition will remain visible when MaxLines is set to 1
(although you may be able to play with that using your posted API code).
And, of course, you need to fix the maximum number of lines that can be
typed in when in "multiline" mode. If you can live with these restrictions,
give the example code below a try.
Rick
Start a new project. Add a TextBox to the form and set its MultiLine
property to True and set the ScrollBars to 2-Vertical. Then paste this code
into the form's code window.