Change text box to autofit, expand

JimmyFo

Member
Joined
Aug 15, 2005
Messages
13
Programming Experience
1-3
Hi, if I am developing a windows application and I want to have a text box that reaches from the top of the app to the bottom (with a margin of ten pixels on the top, bottom, and right, and to cover approx 50% of the app) and auto resizes when the window does, how do I do it? When I drop a text box in, it does not give it multiple lines, and when the app is resized, it can vanish from it. Any ideas?

Thanks,
James
 
You could add a split container on your form, put your textbox in panel 2. Set the textbox dock property to fill, and the multiline prop to true. Then set the panel2 padding props as desired. Also set the minimun panel size if you want to make sure your textbox doesn't disappear
 
You use a TableLayoutPanel for this. Add a TLP to your form, giving it one row and two columns. Set the width of each column to 50% and the Dock property of the TLP to Fill. Now add a TextBox to the right-hand cell. Set its Margin property to 10 for the top, bottom and right and zero for the left. Set its Multiline property to True and resize it until the snap-lines kick in and set its distance from the container to the margin values. Now set the Anchor property to all sides and you're done. As you resize the form the TextBox will automatically resize to occupy the entire right side of the form with the appropriate margin.

Note that a TLP can only support a single control in each cell. That measn that if you want multiple controls on the left hand side you'll have to add a Panel as the single control in the TLP cell first, then add other controls to that Panel.

Note that there's an episode dedicated to the TableLayoutPanel in the VB Express beginner's video series.

http://msdn.microsoft.com/vstudio/express/vb/learning/
 
Back
Top