Introduction: Extra Visual Basic Tips

Hi. This is a tutorial that will give you some extra tips when making an application in Visual Basic. This is be helpful if you are new to Visual Basic.

You will need:
- Computer
- Microsoft Visual Basic
- I recommend you do my previous tutorial if you are new to Visual Basic (https://www.instructables.com/id/Tic-Tac-Toe-Game/)


Legend:
- Bold Text - Code
- Italic Text - Explanation

Step 1: Exit and Back Buttons

You can use Exit and Back button in any application. A Exit button is a button that closes the application when it is clicked. A Back Button is a button that takes you back when it is clicked.

Exit Button: The way the Exit  Button works is that it will close all Forms that are in the Application. For this tutorial I will have 2 Forms in the application, they will be names 'FormOne' and 'FormTwo'

1. Create a Button and make the text 'Exit' and the name 'ExitButton'. This is for easy coding.

2. Double click the button to bring up the code for the button when it is click; or write the following code:

'This is the code for the button when it is clicked'
Private Sub ExitButton_Click(sender As System.Object, e As System.EventArgs) Handles ExitButton.Click

End Sub


3. The following code is to close all the Forms in the application.

'If the Button is in FormOne then write:
Me.Close()
FormTwo.Close() 

'if the button is in FormTwo then write:
Me.Close()
FormOne.Close()


Note:
'Me' refers to the Form that the code is in.
'.Close' is the code to Close what is in front of the dot.
__________________________________________________________________________________________________________

Back Button: The way the back button works is that it will hide the form that is opened and show the previous form.

1. Create a Button and make the text 'Back' and the name 'BackButton'. This is for easy coding.

2. Double click the button to bring up the code for the button when it is click; or write the following code:

'This is the code for the button when it is clicked'
Private Sub BackButton_Click(sender As System.Object, e As System.EventArgs) Handles BackButton.Click

End Sub


3. The following code is to hide the opened form and show the previous from application.

'If the Button is in FormOne then write:
Me.Hide()
FormTwo.Show()


'if the button is in FormTwo then write:
Me.Hide()
FormOne.Show()


Note:
'Me' refers to the Form that the code is in.
'.Hide' is the code to Hide what is in front of the dot.

Step 2: Colour

You can change the background colour. This can be used in any application and gives the user a customisable user interface. This is very easy to do. I will show you the code that will change the colour. There are many different ways to implement this, you can use button or a list so I will leave that up to you. Just put the following code in the Private Sub of your method.

Background Colour: This is to change the colour of the form.

The following code is to change the background colour. For this tutorial I will have 2 forms, one named 'FormOne' and the other 'FormTwo'. I will be changing the colour to Plum.

'If you would like yo change the colour of the form that the code is in you will have to use Me.'
Me.BackColor = Color.Plum
FormTwo.BackColor = Color.Plum


Step 3: Changing Text

changing text can help a lot and is very us full to know how to do, this is very easy. This was used in my Tic Tac Toe game when the player who goes first was chosen.

For this example I will change the text of the label on a click of a button.

1. Create a label and button.

2. Make sure the name of the is 'Label1' and the name is the button is 'Button1'.

3. Make the text on the label "On". 

4. Double click on the button to bring up the code.

5. insert the following code in between Private Sub and End Sub:

'If the text is "On" it will change it to Off. If it is not "On" it will change it to "On"
If Label.Text = "On" Then
     Label1.Text = "Off"
Else : Label1.Text = "On"