Forms in Visual Basic

Note: There are 2 ways to show a form: modal and non modal. Modal means that the program that shows the form waits until the form is closed to continue processing. This is similar to the way a message box and input box are displayed. The method ShowDialog displays the form modally. The method Show() simply displays the form.


The next example uses the Show method and also sets several properties of the form before displaying it.
1. Start a new Windows application called WeatherForms.
2. Right click each of these pictures and save them to your computer:

cloud rainsnowsun
3. Build the main form as shown and described below:

Create the first button with the following properties, then copy and paste to create the rest. The buttons are named BtnClouds, BtnSnow, BtnSun, and BtnRain.
TextAlign: BottomCenter
Tag: 0 (on the first)
Important: The Tag property will be used to create an array. Assign the values 0, 1, 2, and 3 as the tags for the four buttons.

Select the image property for each button and import the images. Select a different Background for each button.

4. From the menu select Project, Add Windows Form…Select Windows form from the pop up. Type FrmWeather as the name of the new form.
5. Build FrmWeather with one label named LblInfo with AutoSize=False, stretch the size so that 2 lines will fit. Add a PictureBox named Pic. Set SizeMode to StretchImage.

There is no code for FrmWeather.

NEXT: Show Form