Saturday, March 10, 2012

The basic

2. The basics
Now we are going to learn the basic of the Visual Basic programming
Today we will use :
  • Button
  • PictureBox
  • TextBox and 
  • Label


2.1 OK, lets start by adding a textbox, a label and a button to our project new project.


Try to make the form like this.
Change the label text to blank.






Textbox - here we will enter our name
Button - after we push the button the label text will change "Welcome MyName.How are you today?"
Label - it will show the text

Code:

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If Not TextBox1.Text = "" Then
            Label1.Text = "Welcome " & TextBox1.Text & ". How are you today?"
        Else
            Label1.Text = "Please enter your name."
        End If
    End Sub

'The IF event will check did we wrote our name or we left it blank if we left it blank the label text will change to 
"Please enter your name", if we wrote our name label text will change to ex. "Welcome Gabriel.How are you today?"

Case 1 - If we write our name 


Case 2 - If we don't write our name



2.2 In the same project add a picturebox (resize the form if needed)
After we placed our picture box we will add a picture to it. Click on the picture box, go to properties, and click the where it says "Image". Press the "..." and select any picture you want. 

And that is it, easy right? Hope you learned something. =)




No comments:

Post a Comment