Question Change form size with textbox?

Lilium

New member
Joined
Jan 18, 2013
Messages
1
Programming Experience
Beginner
I know it's a pretty newb question but how do I change the form size with a textbox? Thanks.
 
As with all problems, break it down. There are multiple steps in there and each one can be addressed individually.

1. To change the size of a form you can set its Height or Width property individually. If you want to change both, create a new Size object and assign it to the Size property of the form.

2. The text displayed in a TextBox is represented in code by its Text property. You get the property value to retrieve what the user has entered and you set the property to display new text to the user. The Text property is type String, so you can use it like you would any other String.

3. A String can contain any text at all, while the Height and Width of a form must be Integers. That means that you will need to convert from String to Integer. There are numerous ways to do that. If you have been instructed to work under the assumption that the user will enter valid data then you can simply use CInt. Be aware though, if the user does enter invalid data then your app will crash. In a real-world app you would use Integer.TryParse, which will validate the data first, allowing you to ignore invalid data or notify the user, and output the result if it passes.

4. You need to decide when the change will occur. It might be every time the user makes a change in the TextBox, but that is probably a bad idea because you will see many intermediate changes if they type several digits. You would most likely want to make the change when they click a Button to confirm the value they've entered. Whatever you prompt you choose, you need to find the corresponding event and handle it, then put your code to make the change inside that event handler.
 
You will also want to make sure the size entered is within the correct range, not too big and not too small. I would use two NumericUpDown controls, not a textbox, one for the height and one for the width. The valid range (minimum & maximum) can be set in the property window during design time.
 
Back
Top