Multiple Forms and Printing a Form

 

Multiple Forms

Part 1 Adding more forms

 

All Visual Basic Programs start with one form but it is possible to add more than one form

Start a New Project in Visual Basic… Lets add 2 more forms for a total of 3

 

Click here to add another form… Make it a standard .exe type.. Repeat for the third form

 

Notice we now have three forms in the project window

 

 

Lets rename each of the forms as follows

 

Form1 will be frmIntro

Form2 will be frmMain

Form3 will be frmEnd

 

 

Part 2  Controlling which form starts up first…..

 

Choose Project - Properties

to see

By default form1 which is no called frmiIntro  is always the first form so you shouldn’t have to change anything.

 

Part 3  Moving from form to form when the program is running.

 

Setup the 3 forms in the following way..

 

On form 1 place a label that says “Intro” and a command button that says “Click to Enter”

On form 2 place a label that  says “Main” and two command buttons.  One says “Goodbye” and the other “Print”

On form 3 Place a label that says “Thx for using this program” and a button that says “End”

 

Name each of the command buttons in an appropriate manner…  cmdEnter, cmdGoodbye, cmdPrint, cmdEnd

 

You might have something that looks like these three forms with the code that goes with them

 

  

 

Lets enter the code for these three forms starting with frmIntro

 

Private Sub cmdEnter_Click()

'will show the main form for the program

 

frmMain.Show  'shows the Main form

frmIntro.Hide  'hides the intro form

 

End Sub

 

 

 

Private Sub cmdGoodbye_Click()

'will show the ending form for the program

 

frmEnd.Show  'shows the ending form

frmMain.Hide  'hides the Main form

 

End Sub

 

Private Sub cmdPrint_Click()

'prints the form

 

frmMain.PrintForm   'prints the form

 

End Sub

 

 

Private Sub cmdEnd_Click()

 

End 'closes the program

 

End Sub

 

So there you have it.  You can now add more forms, control which ones are shown and print the forms