Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  Moving between forms in VB.NET (Monday, January 02, 2006)




Found the following interesting discussion in the Newsgroups:

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:

Anonymous James Mouchett said...

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

3:45 PM  

Post a Comment

 
Previous Posts
    - Is form closed?
    - Determine if property exists at runtime?
    - How to convert VB6 Type To .NET Structure
    - How to create a suimple virtual directory with def...
    - Multi column listboxes
    - Unicode to MS-DOS Cyrilic (code page 866)
    - Vb.net 2003 Get Text File
    - Program upgrades
    - RE: SQLCE Problem on Create Table
    - Q:Importing an Excel file into a VB application

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006

Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland