In this tutorial we will look at how to create a Windows Form and how we can dynamically change it’s appearance through the code-behind, as well as look at creating a custom Exit Application button, and message boxes. VB version.

This tutorial will serve as an introduction to programming for the Windows platform. In this tutorial we will learn such basic things as how to create a Windows Form and how to dynamically change the Header Title and dimensions of the form and the background color, as well as how to make use of message boxes and how to create an exit application button.

When working in the code-behind of the form (Form1), we can reference the form itself simply using the keyword Me. For example, we will resize the form when it is loading with the following code:

The first line of this code simply sets the Title of the Form. The other four lines of code set the position and dimensions of the Form.

Next, we will add functionality to detect when the user clicks anywhere on the Form, and tell them. First, we add the following in the Form Load event:

Then we add the ClickForm Event Handler:

Finally, we will create a friendly Exit button for the user. And before the application exits, we will notify the user.

We drag a button onto the Form Design view from the toolbox, then double click it to create a handler:

The entire code-behind will look something like this:

Download Source Files