Home and Learn: VB Net Course
Instead of double clicking the Button tool in the toolbox to add the control to the form, we'll explore another way to do it.
With your Form displayed in the Visual Basic Design environment, do the following:
You can use the above method to draw most of the controls onto the form - labels, Buttons, textboxes, etc.
The Button control, just like all the other controls we've seen so far, has a list of properties. One of these properties is the Text property. At the moment, your button will say "Button 1". You can change that to anything you like.
Now add a Textbox to your form using one of the methods outlined (either double-click, or draw).
Your Form should now look something like this:
The Font property of the Button has also been changed, here, in exactly the same way as we changed the Font property of the Label and Textbox previously. The Text for the Textbox control has had its default Text (Textbox 1) deleted.
To get our first look at the code window, double click your Button control. The code window will appear, and will look something like this:
The part to concentrate on for the moment is where your cursor is flashing on and off. Because you double-clicked the Button control, the cursor will be flashing between the lines Private Sub and End Sub.
Here's the part we're concentrating on:
Private Sub Button1_Click(sender As Object, e As EventArgs) _
The part of the code we're interested in is highlighted in red in the code above. Notice, too, that the underscore character ( _ ) has been used to spread the code over more than one line. You can do this in your own code, too, if it becomes to long:
Don't worry if you don't understand all of that. It will become clearer later. Let's add our code, which we'll do on the next page.
Buy the Book of this Course
Email us: enquiry at homeandlearn.co.uk