Moving between forms in VB.NET by:stmthoma@gapac.com (Steven Thomas)
|
Ok, I am a newbee at vb.net and I have written an application with multiple forms. I have created a form named frmbase with all other forms are inherited from. frmbase has my menu on it. I have set frmbase as the startup form. This all works great, however when I go to form 2 I get a new window, and I would like for it to stay in the same window that frmBase was in so I don't have lots of windows open as a user is working.
Can someone point in the right direction to do this?
Thanks
|
| | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
|
| |
Instead of designing forms, design usercontrols that are dynamically instantiated/removed from the form.
-- Herfried K. Wagner [MVP]
|
| | Reply: by:Steven Thomas
|
| | Sounds good but I have about 20 forms built and working. Is there not a better way to do this? If not is there and easy way to covert my forms to controls?
Don't just participate in USENET...get rewarded for it!
|
| | Reply: by:Chris Dunaway
|
| | On Wed, 16 Jun 2004 09:26:19 -0700, Steven Thomas wrote:
One method is to open the forms inside the main form. In the main form, add a panel to hold the other forms.
For each of the other forms, set their border style to None.
Then to load the form into the panel, do something like this (check syntax)
Private Sub LoadFormIntoPanel() Dim MyForm2 as New Form2 MyForm2.Size = pnlContent.Size MyForm2.TopLevel = False MyForm2.Parent = pnlContent MyForm2.Show End Sub
This code will show the form inside the panel. Be sure that, as you load and unload forms, you dispose of them properly, etc.
This should give you some ideas. I don't know if it's better, but you wont have to change your forms. -- Chris
|
| | Reply: by:stmthoma@gapac.com (Steven Thomas)
|
| | Chris Thanks for then info. It seems simple enough. However I got the first form to load in the panel. Then how do I close it and load the second. I don't seem to be able to determine which form is loaded and how to close it?
|
1 Comments:
To address loading and unloaded (i.e. showing and hiding multiple forms) you can use the following code sample.
Private Sub ShowForm(ByVal FormName As String)
' Used for incrementing through all the forms.
Dim A As Integer = 0
' Used for holding the integer index of the form
' you wish to show.
Dim ShowIndex As Integer = 0
' Loop through all of the forms.
For A = 0 To Forms.GetUpperBound(0)
' Check to see if the form name matches the
' form you are looking for.
If Forms(A).Name = FormName Then
' Store the index of the form that you
' found a match to.
ShowIndex = A
Else
' Hide all other forms from the operator.
Forms(A).Hide()
End If
Next
' Adjust the size of the form to match the size
' of the panel you wish to show the form in.
Forms(ShowIndex).Size = Panel1.Size
' Set the TopLevel property of the form to false.
Forms(ShowIndex).TopLevel = False
' Set the Parent property of the form to the
' specified panel.
Forms(ShowIndex).Parent = Panel1
' Show the form that matched the request passed to
' the subroutine.
Forms(ShowIndex).Show()
End Sub
Post a Comment