After Unhiding a Form How to Load It Again in C


Purchase and download the fully updated Visual Basic 2010 edition of this eBook in PDF and ePub for only $9.99


When developing a Windows application using Visual Basic it is highly likely that the awarding will consist of multiple forms (otherwise known every bit windows). Information technology is unlikely, still, that all of those forms will need to be displayed as soon every bit the application starts upwardly. In fact, it is more probable that most of the forms volition remain hidden until the user performs some action that requires a class to be displayed.

In this chapter we will cover the topic of hiding and showing forms when developing applications in Visual Basic.

Contents


Creating a Visual Basic Application Containing Multiple Forms

Before nosotros can look at hiding and showing Forms nosotros start need to create an application in Visual Studio which contains more than one form. Begin past starting Visual Studio and creating a new Windows Application project chosen vbShowForm (come across Creating a New Visual Basic Project for details).

Visual Studio will prime the new project with a single form. Click on the Form to select it and, using the Properties console change the Name of the form to mainForm. Next we demand to add a second course. To practice this, click on the Add New Item in the Visual Studio toolbar to invoke the Add New Particular window:

Visual studio add new item.jpg

The Add together New Item window allows new items of various types to be added to the project. For this example nosotros just need to add a new Windows Form to our application. With Windows Form selected in the window click on Add. Visual Studio will now display an additional tab containing the second form:

Visual studio two forms.jpg

Switch betwixt the ii forms by clicking on the respective tabs. With Form2 visible click on the form and change the name of the course in the Properties panel to subForm.

Now that y'all have created two forms, add a Push to each form by displaying the Toolbox and dragging a Push onto each form.

Now that nosotros have created an awarding with ii forms the side by side stride is provide a mechanism for hiding and showing subForm. Before doing that, however, we first need to understand the deviation between modal and not-modal windows.

Ezoic

Understanding Modal and Non-modal Forms

A Windows form can exist displayed in one of 2 modes, modal and not-modal. When a form is non-modal it ways that other forms in the other forms in the application remain accessible to the user (in that they tin nevertheless 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 consummate a chore earlier proceeding to some other part of the application. In the following sections we will cover the creation of both modal and non-modal forms in Visual Bones.


Writing Visual Bones Code to Display a Non-Modal Form

Nosotros are going to use the button control on mainForm to brandish subForm when it is clicked by the user. To do this, double click on the push button control to display the Click upshot procedure. In this upshot process we want to call the Show() method of the subForm to brand it display. To achieve this, modify the Click() issue handler as follows:

Private Sub Button1_Click(ByVal sender As Organization.Object, ByVal e Equally System.EventArgs)            Handles Button1.Click          subForm.Show()  Finish Sub        

To examination this code printing F5 to compile and run the application. When it appears click on the button in the main form and the sub course volition appear. You will observe, since this is a not-modal form, that you lot tin can however interact with the primary form while the sub-form is visible (i.e. you can still click on the button in the primary class).

Close the running application.

Writing Visual Basic Lawmaking to Display a Modal Course

We volition at present modify the event process for the button to create a modal form. To do and then nosotros need to phone call the ShowDialog() method of the subForm. Modify the Click event procedure of the mainForm button equally follows:

Individual Sub Button1_Click(ByVal sender As Organisation.Object, ByVal e Every bit Organisation.EventArgs)                  Handles Button1.Click          subForm.ShowDialog()  End Sub        

Press F5 once once more to build and run the awarding. After pressing the button in the main course to display the sub course you will detect that the main course is inactive every bit long as the sub grade is displayed. Until the sub form is dismissed this will remain the case.

Close the running application.

Hiding Forms in Visual Basic

There are two ways to make a grade disappear from the screen. 1 fashion is to Hide the form and the other is to Close the course. When a form is hidden, the form and all its properties and settings all the same be in memory. In other words, the form still exists, it is merely not visible. When a form is closed, the form is physically deleted from retentiveness and volition need to be completely recreated before it can exist displayed again.

To hide a form it is necessary to call the Hide() method of the course to be subconscious. Using our instance, we volition wire upwardly the push on the subForm to close the course. Click on the tab for the second course (the subForm) in your pattern and double click on the button control to display the Click upshot procedure.

Ane very important point to annotation hither is that the button control is going to hide its own Form. In this case, the event procedure must reference Me instead of referencing subForm past proper noun. With this in mind, modify the procedure every bit follows:

Private Sub Button1_Click(ByVal sender As Organization.Object, ByVal eastward As System.EventArgs)                 Handles Button1.Click          Me.Hide()  End Sub        

Press F5 to build and run the application. Click on the push button in the main form to display the sub form. At present, when yous press the push button in the sub form, the grade will exist hidden.

Closing Forms in Visual Bones

As mentioned in the previous section, in lodge to remove a grade both from the display, and from memory, it is necessary to Close rather than Hide it. In Visual Studio double click, once once again, on the button in subForm to view the Click outcome process. One time once again, because the push button is in the form nosotros are endmost we need to use Me instead of subForm when calling the Shut() method:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Organization.EventArgs)               Handles Button1.Click          Me.Shut()  Stop Sub        

When the subForm push button is pressed the grade volition be closed and removed from retentivity.

Purchase and download the fully updated Visual Basic 2010 edition of this eBook in PDF and ePub for only $9.99

shermanhouldlat.blogspot.com

Source: https://www.techotopia.com/index.php/Hiding_and_Showing_Forms_in_Visual_Basic

0 Response to "After Unhiding a Form How to Load It Again in C"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel