VB Logo

Tutorial: Working with Multiple Forms


The objective of this tutorial is to learn how to create a multi-form application and to navigate between the forms at run time. At the end of this tutorial you should be able to:

Adding new forms to an application

When VB is launched it provides a blank form called Form1. All but the most trivial programs consist of more than one form. For example, it is common to have a welcome screen offering a number of options and for each of these to branch to different forms. The high level structure of an interactive application can often be understood best from a diagram showing the forms hierarchy. Imagine a computer-based learning package containing a number of modules, each of which has a number of forms associated with it.


Task

Just to get the idea of creating multi-form applications quickly, create a master program to contain several of the tutorial exercises completed already.

Start a new project. The first form should be a welcome screen (called frmWelcome), use graphical techniques to make it look attractive. Include on the form three command buttons with appropriate pictures on them to represent the applications you want to include (perhaps the language tutor, restaurant program and animation program). Add a Quit button to terminate the program.

Using the Add File option, load the forms for these applications into your project. The forms will have to have unique names before you load them - hopefully they have been named sensibly and are not all called Form1!

Code the command buttons on the welcome screen to hide that screen and show the appropriate next one.

If the subsequent screens have Quit buttons, change the captions on these and program them to return to the welcome screen. If not, add new buttons to perform this function.

If public variables have been used you will need to preserve these in a shared Module1.bas, resolving any duplicate names.

Screen hierarchy

See if you can work out how to return the program automatically to the welcome screen if there is no interaction from the user for one minute. Hint: You will need to use the Timer control , the MouseMove event and a global variable to act as a ‘clock’. Please read Timing events in Visual Basic or use VB’s online help to find out how the Timer works.



See also Tutorial 14: Multiple Document Interface (MDI)

Tutorial 8 (Animation and Graphics)
Menu
Tutorial 10 (Using the Grid Control)