Home and Learn: VB Net Course

The Form Load Event in VB .NET

An important event you'll want to write code for is the Form Load event. You might want to, for example, set the Enabled property of a control to False when a form loads. Or maybe blank out an item on your menu. You can do all this from the Form Load event.

Add another button to your form for this example, and we'll see how the Form Load event works. (If you haven't been folowing along, create a new project and add two buttons to it.

Bring up your coding window, and select the Form1 Events from the drop down box:

Form1  Events selected from a dropdown list

In the events drop down box, select Load:

The Load item selected from a dropdown list of Events

A code stub for the Form Load event is then added to your code. Type in the following as the code for the Load Event:

MessageBox.Show("Form Load Event")

Run your programme. You should see the message box display before the Form loads.

To switch off your second Button before the Form loads, add this to your code:

Button2.Enabled = False

Run your programme again. You should see that button is no longer available for clicking on.

We'll now up the pace a bit. We'll have a look at just what Objects are, and how you can create your own.

Back to the VB NET Contents Page


Buy the Book of this Course

Email us: enquiry at homeandlearn.co.uk