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

08-08-2002, 09:22 AM
|
|
|
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.
|
|

08-08-2002, 10:31 AM
|
 |
Ultimate Contributor
|
|
Join Date: Nov 2002
Location: England
Posts: 2,747
|
|
Code:
Dim X As New Form1 X.Show()
|
|

08-08-2002, 11:45 AM
|
|
|
|
|
Thank You!!! But, how do you get the current form to unload??
|
|

08-09-2002, 08:56 AM
|
|
|
|

08-09-2002, 09:15 AM
|
|
|
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!!
|
|

08-09-2002, 11:59 AM
|
 |
Exalted One
Preferred language: C#
|
|
Join Date: Nov 2002
Location: Rhode Island, USA
Posts: 1,877
|
|
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.
|
|

08-14-2002, 01:15 PM
|
|
Freshman
|
|
Join Date: Feb 2002
Posts: 46
|
|
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!
|
|

08-14-2002, 01:50 PM
|
|
|
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.
|
|

08-14-2002, 01:58 PM
|
 |
Exalted One
Preferred language: C#
|
|
Join Date: Nov 2002
Location: Rhode Island, USA
Posts: 1,877
|
|
...will completely close any application with or without multiple windows.
|
|

08-15-2002, 09:49 AM
|
|
Freshman
|
|
Join Date: Feb 2002
Posts: 46
|
|
If I do a simple:
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.
|
|

08-15-2002, 10:01 AM
|
|
|
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??
-
|
|

08-15-2002, 03:35 PM
|
|
Freshman
|
|
Join Date: Feb 2002
Posts: 46
|
|
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?
|
|

08-16-2002, 06:20 AM
|
|
|
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...
|
|

08-16-2002, 06:49 AM
|
|
|
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
|
|

08-16-2002, 09:25 AM
|
|
Freshman
|
|
Join Date: Feb 2002
Posts: 46
|
|
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.
|
|

08-16-2002, 09:32 AM
|
 |
Ultimate Contributor
|
|
Join Date: Nov 2002
Location: England
Posts: 2,747
|
|
Try changing your startup object to Sub Main, then you can have a more objective approach to what forms you load and when.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
| |
|
|
|
 |
|