Professional Documents
Culture Documents
NET)
12
Multiple Forms
Create a new form Reference one form from another Share data between forms
Page 1 of 4
A number of points. 1. 2. 3. 4. The start up object can be either a form or sub Main in a module. The default is Form1. If you rename Form1 you need to re specify the start up object. If VB.NET cannot find the start up object it will try to start sub Main
Page 2 of 4
To create a second form you need to click on Project | Add Windows Form. Click Open to the dialog box that appears and a new Form2 will be generated in the main edit screen and will also appear in the Solution Explorer Window.
To make MyForm2 visible, for example on the click of a button, you need to add the following code Private Sub Button1_Click(. . My.Forms.Form2.Show() Me.Hide() End Sub .) Handles Button1.Click
Try running this program and when you click the button on Form1, Form2 will be displayed, and Form1 will be closed. Now try changing the code behind the button slightly to open the second form as a dialog box. Private Sub Button1_Click(. . .) Handles Button1.Click My.Forms.Form2.ShowDialog() End Sub How does this affect the behaviour of your program? When do you think you would use the ShowDialog function in preference to the Show function?
Page 3 of 4
Module Module1 Public products As New ArrayList Public item As String End Module In this example, two variables have been declared, an array and a string variable.
Page 4 of 4