Tutorial Level: Beginner: Add to your first program (Getting used to Code)
I hope you have read the first tutorial, we are now going to add to that.
1.) We have already discussed how to add controls (button, textbox, label to the form), just drag and drop.
2.) First lets creat our form, or the backbone of the program, File, New, WindowsApplication.
3.) Click on the form, only once because twice will take you to code view.Then go to the right to the properties tab.
Play with the settings, they are prety self explanatory.
4.) Now add a TextBox, Label, and Button. What our program is going to do is let the user type something in the TextBox, press the button, and make
that text appear on the label.
5.) Think about what your program needs to do and take it one step at a time. First the user types something, that takes no coding, then he presses
the button, and makes it go on the Label, this takes coding.
6.) Double click on the button on the form, so that you are in code-view. Under all the Private Sub Button1_Click crap, type this code:
Simple and Self-explanatory right? It simply sets the Label's text equal to the TextBox text when the button is being clicked.
7.) Run your program using the green arrow near the top.
Type something in the TextBox, press the Button, and TaDa!!!
8.) Now lets stretch this out a bit since this lesson IS about coding. We are now going to "Hide" the TextBox.
9.) Under the Label1.Text = TextBox1.Text
Type this code:
Again, self explanatory, run the program, it will disappear when the button is clicked.
10.) OK, now lets get our TextBox back!
Add a new button by swithcing back to designer mode using the tabs
Double click the button you just added, and lets add some more code.
Below Private Sub Button1_Click blah blah blah type
More simple code that simply reshows our TextBox.
11.) Many programs use more than one form, so lets add one more, go to Project at the top, then Add Windows Form, this will add a new form, form2.
12.) Make a new button on the form, and in the code, type
This obviously shows Form2.
You can also close the first form by typing
"Me" simply means you are coding in that particular form.
Now you can add more buttons, textboxes, labels, and simply change the code around, hide them, show them, the possibilites are endless.
Check in for more,