Methods and Objects
Methods and Objects are predefined working for a control. Each method have its own properties and code procedure. These codes are executed when user invokes a method.
Its known as Method Call. Methods and Objects are very important to use when creating an event driven program. Visual Basic is an event driven language.
Event driven mean our code or software will work only when a specific event will occur. We define these events while coding the application as applications requirements.
Let me tell you in little bit details about methods and objects. Actually when you click on a button in any program you get some results or actions.
For example in last lesson we created a Hello Word program. In that program when we click on button we can see a popup message saying hello world.
Here in this program we click exit button to exit the application.
We can say this time that button is an Control and Click is its event and as in code we typed Form1.hide here form1 is object and .Hide is method.
Below is Method Calling basic syntax
Properties are attributes for an object but method is working for and object.
If we code a program to hide command button we will write code as under.
Here command1 is object which is a command button and hide is a method
you can see events here in screen shot below
A mouse click, a key press, loading form, hiding form, moving mouse to a form or control even double clicking to a control these are all called events.
In visual basic you can attach code to any event of your choice or according to your requirements.
For example if you want to show a popup message to user when he start your program
Then you have to add code in load event of related form. In same way if you want to show message on exit of any program then you have to code in form hide event or in form unload event.