Review of Classes
A class is a blueprint for an object. The actual object is created from that blueprint when we Dim a new object as the class. A class can inherit capabilities from a parent, or base, class. The form that C# creates for us, inherits all of its capabilities from the base class (Form) in the .Net Framework DLL's.
A class can have properties to allow programmers to get/set different attributes as we do at design time. The variables that hold the property values in our class are set from the properties...that is the only way the outside world can change values inside the class.
A class also has code that instructs it to do things. From outside the class, these actions are known as methods. Inside the class, we create & call them subroutines and functions.
A class has a constructor called Sub New that builds an object from the class. It also has a destructor called Sub Dispose that removes references to it so the O/S can remove it from RAM.
When you want a new instance of a class, the New keyword usually will call a function named Sub Main, which in turn calls Sub New. If the class inherits from a parent class, the first line in the constructor calls the constructor of the parent class.
System.Windows.Forms.Application.Run(New Form1) is in charge of running the program. The Application object's Run method calls Form1's constructor to build the class. Then the Run method executes an internal message loop that looks for Windows messages directed at Form1. When the Run method receives a message such as a button click, it directs the message to the form, which further directs the message to the button. The APP object (as we call it) communicates with the O/S and directs any messages to/from the forms so the controls can respond to the user's keyboard/mouse actions.
An event notifies our program that something interesting has happened. Our program finds out about events from the Application.Run method.
When we need to hide data within our class, the Private keyword is used. We can also use Public, Protected, and Friend modifiers to Sub routines.
Using the Shared keyword when we Dim a variable, makes sure that all the instances of the Form1 class use this same variable. We might keep track of total sales, for instance. In this case, no matter how many instances of our class are instantiated, there will be one "global" variable to keep track of our running total.