Guest JonM Posted August 8, 2002 Posted August 8, 2002 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. Quote
*Gurus* divil Posted August 8, 2002 *Gurus* Posted August 8, 2002 Dim X As New Form1 X.Show() Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Guest JonM Posted August 8, 2002 Posted August 8, 2002 Thank You!!! But, how do you get the current form to unload?? Quote
Guest JonM Posted August 9, 2002 Posted August 9, 2002 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!! Quote
*Gurus* Derek Stone Posted August 9, 2002 *Gurus* Posted August 9, 2002 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. Quote Posting Guidelines
shootsnlad Posted August 14, 2002 Posted August 14, 2002 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: 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! Quote
Guest JonM Posted August 14, 2002 Posted August 14, 2002 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. Quote
*Gurus* Derek Stone Posted August 14, 2002 *Gurus* Posted August 14, 2002 Application.Exit() ...will completely close any application with or without multiple windows. Quote Posting Guidelines
shootsnlad Posted August 15, 2002 Posted August 15, 2002 If I do a simple: frmmain.hide() I will get the following error on that line: 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. Quote
Guest JonM Posted August 15, 2002 Posted August 15, 2002 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?? - Quote
shootsnlad Posted August 15, 2002 Posted August 15, 2002 I checked the name of the public class. It appears to me to be the same. Here is the exact coding I am using: 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? Quote
Guest JonM Posted August 16, 2002 Posted August 16, 2002 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... Quote
Guest JonM Posted August 16, 2002 Posted August 16, 2002 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 Quote
shootsnlad Posted August 16, 2002 Posted August 16, 2002 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. Quote
*Gurus* divil Posted August 16, 2002 *Gurus* Posted August 16, 2002 Try changing your startup object to Sub Main, then you can have a more objective approach to what forms you load and when. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.