Free computer Tutorials

home
Stay at Home and Learn

Adding a Tool (Control) to your Form

 
Computer Tutorials List

 

 

 

 

 

How to Add a Control to your VB .NET Forms

 

Let's start by adding a textbox to our form. With the tools displayed, do the following:

  • Locate the TextBox tool
  • Double click the icon
  • A textbox is added to your form

The textbox gets added to the top left position of your form. To move it down, hold your mouse over the textbox and drag to a new position:

VB NET Form with One TextBox

Notice the small squares around the textbox. These are sizing handles. Move your mouse over one of them. The mouse pointer turns into an extended line with arrowheads. Hold your left mouse button down and drag outwards. The textbox is resized. Play around with the sizing handles until you're happy with the size of your textbox.

One thing you will notice is that you can't make the size any higher, but you can make it wider. The reason why you can't make it any higher is because the default action of a textbox is to have it contain only a single line of text. If it's only going to contain one line of text, Microsoft reasoned, there's no reason why you should be able to change its height. A textbox can only be made higher if it's set to contain multiple lines of text. You'll see how to do this soon.

You should now have a textbox on your form that looks something like this one:

Move your VB NET TextBox

  • Create two more textboxes by double clicking on the textbox icon in the toolbar (Or Right-click on the selected textbox and choose Copy. Then Right-click on the Form and choose Paste.)
  • Resize them to the same size as your first one
  • Line them up one below the other with space in between
  • Try to create something that looks like the one below

Three Texboxes on a VB NET Form

 

No more reading these lessons online - get the eBook here!

 

Adding a Label to your Form

Let's add some labels near the textboxes so that your users will know what they are for.

  • Locate the label control in the toolbox
  • Double click the label icon
  • A new label is added to your form
  • It should look like the one below

Add a Label to your VB NET Form

The square sizing handles are surrounding the label, and that indicates that a control is selected. Once a control is selected you can do things to it, like resizing the control or moving it.

  • Move your Label to the left of the first textbox
  • If the label stretches over the textboxes, resize it just as you did with the textboxes (You'll notice that the height of the label can be changed, unlike the textbox.)
  • Create two more labels, and position them to the left of the textboxes.
  • You should now have a form like this one

Three Labels on the Form

To see what your Form looks like as a programme, click Debug > Start from the menu bar. Or press F5 on your keyboard:

The Debug menu in VB NET

To stop the programme from running, you can do one of the following:

1. Click the Red X at the top right of your Form
2. Click Debug > Stop Debugging from the menu bar
3. Press Shift + F5 on your keyboard

Stop Debugging

All right, we're getting somewhere. We now have a form with textboxes and labels, something that looks like a form people can fill in. But those labels are not exactly descriptive, and our textboxes have the default text in them. So how can we enter our own text for the labels, and get rid of that default text for the textboxes?

To do those things, we need to discuss something called a Property.

 

<-- Back One Page Move on to the Next Part -->

<--Back to the .NET Contents Page

View all our Home Study Computer Courses