Changes

Jump to: navigation, search

Hiding and Showing Forms in Visual Basic

1,261 bytes added, 17:37, 19 July 2007
Creating a Visual Basic Application Containing Multiple Forms
Switch between the two forms by clicking on the respective tabs. With Form2 visible click on the form and change the name of the form in the ''Properties'' panel to ''subForm''.
 
Now that you have created two forms, add a Button to each form by displaying the Toolbox and dragging a Button onto each form.
Now that we have created an application with two forms the next step is provide a mechanism for hiding and showing ''subForm''. Before doing that, however, we first need to understand the difference between modal and non-modal windows.
 
== Understanding Modal and Non-modal Forms ==
 
A Windows form can be displayed in one of two modes, modal and non-modal. When a form is non-modal it means that other forms in the other forms in the application remain accessible to the user (in that they can still click on controls or use the keyboard in other forms).
 
When a form is modal, as soon as it is displayed all other forms in the application are disabled until the modal dialog is dismissed by the user. Modal forms are typically used when the user is required to complete a task before proceeding to another part of the application. In the following sections we will cover the creation of of both modal and non-modal forms in Visual Basic.
 
== Writing Visual Basic Code to Display a Non-Modal Form ==
 
We are going to use the button control on ''mainForm'' to display ''subForm'' when it is clicked by the user. To do this double click on the button control to display the ''Click'' event procedure. In this event procedure we want to call the ''Show()'' method of the ''subForm'' to make it display. To achieve this, modify the Click event handler as follows:
 
<pre>

Navigation menu