Start new project.
Double click on your main field form. Go to the sub.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
This is one subroutine of Form1. It expects 2 variables (2 parameters). The "sender" variable is declared as an object, while the "e" variable is there to handle an event. The "sender" is called like that because that's the control (object) that sends the triggering event to the same sub, "e" is declared as an event handler which represents an algorithm that expects events (it's used to recognize events and start the sub when they are encountered). EventArgs - stands for: event arguments. Different types of events will require the "e" variable to be declared with a different eventarg declaration - one that is capable of handling the event.
Subs don't return values, they just execute the code written in them after an event.
We can remove the starting event from this sub:
Handles MyBase.Load
If we had some code inside the sub, it wouldn't be executed since the sub wouldn't be able to start like this.We can change the names of the 2 variables: sender and e.
Change them into "bb2" and "ck5". They don't have to be called anything specific.
"Form1_Load" is the name of the sub, not the object. The object name is: Form1.
By default, the name of the sub becomes: (Object Name)_(Starting Event)
After we create the sub, we can change the event it handles and still retain the old name (old event in the name). Obviously, you can name your sub as you like.
Let's call it: F1_Loading
After that, we can display in textual format the values that the 2 variables (the parameters) hold. Add this:
MsgBox(bb2.ToString() & vbnewline & ck5.ToString())
Code:
Public Class Form1
Private Sub F1_Loading(ByVal bb2 As System.Object, ByVal ck5 As System.EventArgs) Handles MyBase.Load
MsgBox(bb2.ToString() & vbNewLine & ck5.ToString())
End Sub
End Class
Private Sub F1_Loading(ByVal bb2 As System.Object, ByVal ck5 As System.EventArgs) Handles MyBase.Load
MsgBox(bb2.ToString() & vbNewLine & ck5.ToString())
End Sub
End Class
Start program. Check the results out.
We will now create a new sub for the same object with a new starting event.
Go to the design page -> Click on the Form1 -> Go to properties window -> Find and click the "Events" icon -> Find: "Doubleclick". You can write your own name for the sub directly - write: F1_DoubleClick and press enter. Or you can just double click on the "Doubleclick" sign on the left and change the name inside the code.
We don't have to change the parameters in this sub: "sender" and "e".
Add the same code as before inside of it:
MsgBox(sender.ToString() & vbnewline & e.ToString())
Code:
Public Class Form1
Private Sub F1_Loading(ByVal bb2 As System.Object, ByVal ck5 As System.EventArgs) Handles MyBase.Load
MsgBox(bb2.ToString() & vbNewLine & ck5.ToString())
End Sub
Private Sub F1_Doubleclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
MsgBox(sender.ToString() & vbNewLine & e.ToString())
End Sub
End Class
Private Sub F1_Loading(ByVal bb2 As System.Object, ByVal ck5 As System.EventArgs) Handles MyBase.Load
MsgBox(bb2.ToString() & vbNewLine & ck5.ToString())
End Sub
Private Sub F1_Doubleclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
MsgBox(sender.ToString() & vbNewLine & e.ToString())
End Sub
End Class
Start program. Double click on the form for second sub.
We will now add a code to the first sub to remove the controlbox from the main form. The controlbox is the part inside the blue header (top form border) that contains the "minimize", "maximize" and "close" buttons. If you click on the main form in the design page -> Properties -> Controlbox -> you can see that is set to "True" which means that is visible (present).
Add this code inside the first sub:
ControlBox = False
Let's turn this line:
MsgBox(bb2.ToString() & vbNewLine & ck5.ToString())
into a comment by adding an apostrophe sign in front of it. This sign is found on the keyboard on the right of number zero. Comments don't get processed by the program, as if they are not there at all.
Second sub add this:
ControlBox = True
Turn this line into a comment too:
MsgBox(sender.ToString() & vbNewLine & e.ToString())
Code:
Public Class Form1
Private Sub F1_Loading(ByVal bb2 As System.Object, ByVal ck5 As System.EventArgs) Handles MyBase.Load
'MsgBox(bb2.ToString() & vbNewLine & ck5.ToString())
ControlBox = False
End Sub
Private Sub F1_Doubleclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
'MsgBox(sender.ToString() & vbNewLine & e.ToString())
ControlBox = True
End Sub
Private Sub F1_Loading(ByVal bb2 As System.Object, ByVal ck5 As System.EventArgs) Handles MyBase.Load
'MsgBox(bb2.ToString() & vbNewLine & ck5.ToString())
ControlBox = False
End Sub
Private Sub F1_Doubleclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
'MsgBox(sender.ToString() & vbNewLine & e.ToString())
ControlBox = True
End Sub
End Class
Start program. The ControlBox shouldn't be there after loading. Double click to make it appear.
If you are ever stuck with a window form without a control box, you will have to use ALT+F4 to close the form.
We will now change this line in the second sub:
ControlBox = True
into:
If ControlBox = False Then
ControlBox = True
Else
ControlBox = False
End IfCode:
Public Class Form1
Private Sub F1_Loading(ByVal bb2 As System.Object, ByVal ck5 As System.EventArgs) Handles MyBase.Load
'MsgBox(bb2.ToString() & vbNewLine & ck5.ToString())
ControlBox = False
End Sub
Private Sub F1_Doubleclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
'MsgBox(sender.ToString() & vbNewLine & e.ToString())
If ControlBox = False Then
ControlBox = True
Else
ControlBox = False
End If
End Sub
Private Sub F1_Loading(ByVal bb2 As System.Object, ByVal ck5 As System.EventArgs) Handles MyBase.Load
'MsgBox(bb2.ToString() & vbNewLine & ck5.ToString())
ControlBox = False
End Sub
Private Sub F1_Doubleclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
'MsgBox(sender.ToString() & vbNewLine & e.ToString())
If ControlBox = False Then
ControlBox = True
Else
ControlBox = False
End If
End Sub
End Class
Start program. Double click to make the Controlbox appear, then double click to make it disappear.
You can change any other True/False option of the form this way. Options like: "MaximizeBox", "MinimizeBox", "ShowIcon".
We can also call the first sub from the second sub. Let's change this two lines inside "F1_Doubleclick":
Else
ControlBox = False
into:ControlBox = False
Else
F1_Loading(0, e) We can also go to the first sub and remove it's starting event:
Handles MyBase.Load
The first sub won't be initialized by an event now.We can also change the opacity and size of the application window.
Go to the first sub and add:
Opacity = 0.75
Me.width = 550
Me.height = 550Code:
Public Class Form1
Private Sub F1_Loading(ByVal bb2 As System.Object, ByVal ck5 As System.EventArgs)
'MsgBox(bb2.ToString() & vbNewLine & ck5.ToString())
ControlBox = False
Opacity = 0.75
Me.Width = 550
Me.Height = 550
End Sub
Private Sub F1_Doubleclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
'MsgBox(sender.ToString() & vbNewLine & e.ToString())
If ControlBox = False Then
ControlBox = True
Else
F1_Loading(0, e)
End If
End Sub
Private Sub F1_Loading(ByVal bb2 As System.Object, ByVal ck5 As System.EventArgs)
'MsgBox(bb2.ToString() & vbNewLine & ck5.ToString())
ControlBox = False
Opacity = 0.75
Me.Width = 550
Me.Height = 550
End Sub
Private Sub F1_Doubleclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
'MsgBox(sender.ToString() & vbNewLine & e.ToString())
If ControlBox = False Then
ControlBox = True
Else
F1_Loading(0, e)
End If
End Sub
End Class
Start program. Try the program out by double clicking.
Opacity is 100% in the code when written like this: "Opacity = 1.0" everything below changes transparency.
The same way we have added 2 events for the main field form, we can add different events for most other controls present in the Toolbox.