Making your first application Instead of doing what most tutorials do and make you make a "Hello World" Application. We are going to skip ahead a bit because you guys seem smart and I know you can handle it. So lets go ahead and open up Visual Studio/Visual Basic. Once you have it open hit New Project and select windows form application. We will call this application Tutp1.
Now you will have a form (Application window within the program) in the top right corner it should say Form1. Click within the centre of this form. To the right of this form you should see the forms Properties window. As show to the right. Along with other options and properties you could change, but for now lets just work with changing the text property of this form. We are going to select the text Form1 and change it to "Click Me Game!" without quotations (area in which you need to change the text is notated with a number 1 in the picture).
Now to the left hand side of Visual Studio you should see a toolbox. If you do not hit "Ctrl + Alt + X" to bring the toolbox side panel up (you can then pin it to stay their with the pin button). Scroll down to common controls in the toolbox window and under it find "Button", now click and drag this onto your form window (IMG right). Do this again for 3 more buttons (IMG down 1). After this we are going to change the area the buttons are located on the form. So move them closer together near the top left a bit. Now click on an empty space in the form window so we have it selected and look in the form windows properties again, this time change Size to "276, 274". Now select the first button and find its Size property as well and change it to "87, 82". Now orientate your buttons the same as the second picture shown at the bottom. If that's good change the Text Property of all the buttons to "Click Me!". After you've done this change every button except "Button1" (so Button2, Button3, and Button4), to have its Visible property to false. Now it's time for some code. Double click the first button (top left most one if you orientated them from 1 to 2 on the top and 3 to 4 on the button if you didn't this could cause problems so do this now), this should bring up the code window you should see some code, continued below.
| |
This window has many other functions we will be looking at on later tutorials. |
|
The code you see should look like this:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class
Now right now it's not to important that you understand everything in this because that's for another tutorial, and that will be our next one. Right now we are just going to focus on the parts between "Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click" and "End Sub". That blank space between their is where we will place our code.
Now since code should always be neat and properly formatted we should give names to all our buttons as the proper format would be (depending on the language and programmer) we would likely call button1 "btn_One" and normally instead of bnt_One it would be more like btn_Submit or btn_okDialog depending on the buttons function we would match its name to sound appropriate and be easy for us to understand later, however for now we will leave it with default names.
So for the code for button one we should have it looking like this:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Visible = True Then
Button1.Visible = False
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
End If
End Sub
End Class
Now at the top you should see tabs one should say Form1.vb [Design] Click that to go back to the form window and see the buttons and now do the same to buttons 2, 3, and 4 changing it so that it would be If Button(button you are working on number) (IE Button2) .Visible = True Then
Button1 = t
true true and then the button you are working on set to false.
If this confused you then the code at the end should look like this:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Visible = True Then
Button1.Visible = False
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button2.Visible = True Then
Button1.Visible = True
Button2.Visible = False
Button3.Visible = True
Button4.Visible = True
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button3.Visible = True Then
Button1.Visible = True
Button2.Visible = True
Button3.Visible = False
Button4.Visible = True
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Visible = True Then
Button1.Visible = True
Button2.Visible = True
Button3.Visible = True
Button4.Visible = False
End If
End Sub
End Class
Now, since I assume you are using Visual Basic Studio Express Edition things might be a little different, but likely not. Now Click the run button and test out your new application (or just hit F5). Try it out, click a button. It should disappear and the rest should be visible, click another, etc etc.
Congratulations, you've just created your first VB application. Hit "Ctrl + Shift + S" and save it as "Tutp1".
If you have any questions comments or concerns post them below, tell me if you think my tutorials are moving to slow or if you want me to go more in depth with some aspects. What are you looking for more? Make sure to tell me so I can adjust these tutorials to suite the needs. Thanks
Right now I'm going to be doing Tut 3 (No Program info on the important parts of programming, what things mean etc) Tut 4 (app) tut 5 ( info on parts of programming) etc. So switching between programs and info. If you would rather more of one or the other be sure to tell me. I'm will assist anyone who had issues with the project as well so post em up!
Also keep in mind I have to start of slow with basics because not everyone has experience with programming. So keep that in mind.
Thanks for reading and happy Programming