Windows Forms Topics include: windows forms, controls, components and designers

Go Back  Xtreme .NET Talk > .NET > Windows Forms > Multiple Forms in .NET


Reply
 
Thread Tools Display Modes
  #1  
Old 08-08-2002, 09:22 AM
JonM
Guest
 
Posts: n/a
Question Multiple Forms in .NET

I have a simple question... I am starting to learn .NET after learning some about VB6. My question is: in VB6, to get a form to unload and another to show, it was really simple. Unload.Me and FORM1.Show. HOw do you get this to happen in .NET????? Nothing I find or read will tell me about working in multiple forms, only one form at a time. And if I try to use the same structure, it errors out on me saying all sorts of nasty things. This gets rather frustrating......
Any help or suggestions would be greatly appreciated.
Reply With Quote
  #2  
Old 08-08-2002, 10:31 AM
divil's Avatar
divil divil is offline
Ultimate Contributor
 
Join Date: Nov 2002
Location: England
Posts: 2,747
divil is on a distinguished road
Default

Code:
Dim X As New Form1
X.Show()
__________________
MVP, Visual Developer - .NET

Now you see why evil will always triumph - because good is dumb.

My free .NET Windows Forms Controls and Articles
Reply With Quote
  #3  
Old 08-08-2002, 11:45 AM
JonM
Guest
 
Posts: n/a
Default

Thank You!!! But, how do you get the current form to unload??
Reply With Quote
  #4  
Old 08-09-2002, 08:56 AM
bananafish
Guest
 
Posts: n/a
Default

Code:
Me.Close
or
Code:
Me.Dispose
Reply With Quote
  #5  
Old 08-09-2002, 09:15 AM
JonM
Guest
 
Posts: n/a
Default

If I use either of these lines, It closes down the whole program. I just want it to close the initial form and show the second.... I am now beginning to rapidly see why people are hating this version of VB!!
Reply With Quote
  #6  
Old 08-09-2002, 11:59 AM
Derek Stone's Avatar
Derek Stone Derek Stone is offline
Exalted One

Preferred language:
C#
 
Join Date: Nov 2002
Location: Rhode Island, USA
Posts: 1,877
Derek Stone is on a distinguished road
Default

Hide the main window instead of closing it. When you close the application's main window the message pump stops, indicating that the program has terminated.
__________________
Posting Guidelines
Reply With Quote
  #7  
Old 08-14-2002, 01:15 PM
shootsnlad shootsnlad is offline
Freshman
 
Join Date: Feb 2002
Posts: 46
shootsnlad is on a distinguished road
Default hiding a form

I, for some reason, am having a very difficult time trying to hide a form. I have 3 forms, 1 of them is the main form. The main form is loaded at startup and then, depending on parameters will load one of the other two forms. The main form should then hide itself. I am able to open either of the two forms OK, but I can't hide my main form. The program won't run when compiled. It errors out on the line that tries to hide the main form. I am basically using this code to his it:

Code:
dim mn as frmMain
mn.hide()

I am simply dimming it as a regular frmMain because it already exists. I didn't think I would want to dim it as a new frmMain, but I believe I have to dim a variable. Correct? Thanks for the help!
Reply With Quote
  #8  
Old 08-14-2002, 01:50 PM
JonM
Guest
 
Posts: n/a
Default

I haven't had a reason to dim the main form yet, but I find that if you use:
-----------------------------------------------------------------------------------

ME.HIDE, ME.VISIBLE = FALSE or FORMSNAME.HIDE
-----------------------------------------------------------------------------------

... it will work. ( at least for me)
Where I have my problem is getting the other forms to close down after being shown, If you hide the main form and put a command button on the second form to close or end the program, it closes the form but keeps the program running in the background with the main form still hidden.
Reply With Quote
  #9  
Old 08-14-2002, 01:58 PM
Derek Stone's Avatar
Derek Stone Derek Stone is offline
Exalted One

Preferred language:
C#
 
Join Date: Nov 2002
Location: Rhode Island, USA
Posts: 1,877
Derek Stone is on a distinguished road
Default

Code:
Application.Exit()

...will completely close any application with or without multiple windows.
__________________
Posting Guidelines
Reply With Quote
  #10  
Old 08-15-2002, 09:49 AM
shootsnlad shootsnlad is offline
Freshman
 
Join Date: Feb 2002
Posts: 46
shootsnlad is on a distinguished road
Default

If I do a simple:

Code:
frmmain.hide()

I will get the following error on that line:

Quote:
Reference to a non-shared member requires an object reference.
I would've thought a simple .hide would've done it, but I always get that error when trying to compile.
Reply With Quote
  #11  
Old 08-15-2002, 10:01 AM
JonM
Guest
 
Posts: n/a
Default

I have checked the code I sent and can get it to work each time fine. The only thing tht I can think of is that the form name that you are referencing is not the same. If you look in the code window for the main form, check that the Public class at the top is the same name as you are trying to use. I have had it where I changed the name of a form and the Public class stayed as 'Form1'. I'm still new at this game also, so hope this helps a little.

-
Also, did the code ME.CLOSE work??
-
Reply With Quote
  #12  
Old 08-15-2002, 03:35 PM
shootsnlad shootsnlad is offline
Freshman
 
Join Date: Feb 2002
Posts: 46
shootsnlad is on a distinguished road
Default

I checked the name of the public class. It appears to me to be the same. Here is the exact coding I am using:

Code:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim args As String
        args = command()
        If args = "/HYDRANT" Then
            Dim hc As New frmHydrantCard()
            hc.Show()
            frmMain.Hide()
        ElseIf args = "/VALVE" Then
            Dim vc As New frmValveCard()
            vc.Show()
            frmMain.Hide()
        ElseIf args = "/STOPBOX" Then
            Dim ts As New frmTapSlip()
            ts.Show()
            frmMain.Hide()
        End If
    End Sub

Can you see anything wrong? I get that above error on all of the .hide lines. I did try to do the me.hide or the me.visible. The me.hide took, but it never hid the form when called upon. The me.visible would not compile. Any ideas?
Reply With Quote
  #13  
Old 08-16-2002, 06:20 AM
JonM
Guest
 
Posts: n/a
Default

The first thing that catches my eye is that you have this in the FORM load Event. I don't know if you can do this. I think it must be under a proceedure event, such as a button click etc... The one line that I don't know how you are trying to use is:

VB:
-------------------------------------------------------------
args = command()
-------------------------------------------------------------

I'm not sure about this or how it's supposed to work.
If this is something that you are to type in, might want to try putting it in a text box.

VB:
____________________________________________________

ARGS = TxtBox.Text
If ARGS = "/HYDRANT" Then
......
____________________________________________________
I'll try the code in one of my forms and see how it does. Other than that, everything looks fine. I'll get back to you when I try it out. Hope this helps...
Reply With Quote
  #14  
Old 08-16-2002, 06:49 AM
JonM
Guest
 
Posts: n/a
Default

Here is the code that I used, It works fine.

VB:
____________________________________________________
Public Class frmMain

Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
args = txtCheck.Text

If args = "Hydrant" Then
Dim hc As New frmHydrantcard()
hc.Show()
Me.Hide()
ElseIf args = "Valve" Then
Dim vc As New frmValveCard()
vc.Show()
Me.Hide()
ElseIf args = "StopBox" Then
Dim ts As New frmTapSlip()
ts.Show()
Me.Hide()
End If
End Sub

End Class
____________________________________________________
I took out some of the code VB puts in automatically to save room on the post, but it works. If you want, I can send you the whole program so you can see what I did. Hope this gets you where you need.
-- JonM
Reply With Quote
  #15  
Old 08-16-2002, 09:25 AM
shootsnlad shootsnlad is offline
Freshman
 
Join Date: Feb 2002
Posts: 46
shootsnlad is on a distinguished road
Default

What I am basically trying to do is to have an outside program call my program with an argument, telling my program which form to display. If the outside program calls my program with a "/HYDRANT" argument on it, then it should load the Hydrant Card form. The only way I could figure out how to do this would be to create a frmmain that: accepts the argument, hides itself and then shows the appropriate form. Since the outside program can't change which form starts up upon launch, I figured the only way would be to have a main form that steers it in the right direction. Thus, I can not use something like a button click event. I know this could be done back in VB 6.0, I just can't figure out how to do it now. Everything works fine with the arguments, I just can't get that frmmain to hide/close/become invisible. It's the only thing that is holding me back. Thanks for the continued help.
Reply With Quote
  #16  
Old 08-16-2002, 09:32 AM
divil's Avatar
divil divil is offline
Ultimate Contributor
 
Join Date: Nov 2002
Location: England
Posts: 2,747
divil is on a distinguished road
Default

Try changing your startup object to Sub Main, then you can have a more objective approach to what forms you load and when.
__________________
MVP, Visual Developer - .NET

Now you see why evil will always triumph - because good is dumb.

My free .NET Windows Forms Controls and Articles
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple forms JoshK Windows Forms 3 04-18-2006 04:30 PM
Need Help With Multiple Forms unknownloser Windows Forms 3 02-20-2005 10:38 AM
Multiple Forms NegativeZero Windows Forms 2 01-24-2005 02:35 PM
Multiple Forms thankins Windows Forms 4 10-29-2003 01:33 PM
Multiple Forms, Array Forms. tcomputerchip Windows Forms 5 12-04-2002 03:22 PM

Advertisement:

Powered by liquidweb