Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Navigating Between Forms 1

Status
Not open for further replies.

aharris2693

Programmer
Jul 15, 2003
45
US
This is my first time using vb.Net, and I am finding it to be quite different from VB6. I currently have a simple problem that jsut doesn't seem to work. If I want to close the current form, (form1), and open the next form,(form2), in VB6 i would simply use Unload Me Form2.show I feel knid of stupid asking how this is done now, but I can't seem to figure it out. Any help would be greatly aprreciated.
 
A form is just another object. So to open it, you create a new instance of the object and use either the Show or ShowDialog method. You can then close the object and set it to Nothing.

Craig
 
Craig,
Thanks for the info. When I use the showdialog method, It opens the new form, but if I close form1, the whole program shuts down. I have two books on VB.net, and neither of them address this at all, they tell you how to open a new form, but not how to close the previous one. There is even a previous thread in this forum that tells how to do this in about 40 lines of code. I may be wrong, but it seems that if you could do it in two lines in vb6, there has to be an easier way in vb.net. Thanks again for the help
 
It will if Form1 is the startup object. Once it has been closed, the second form no longer has a container. Your opening form must be dialog and remain open throughout the program running.

Think about Word. The Word application can hold any number of open documents but if you close Word, all documents close with it. That's what is happening to you. You are opening a form but closing it's container.

What sort of app is it? Can you use an MDI style interface?

Craig
 
Thanks a lot for responding Craig. That explanation clears it up for me. I didn't realize that form 1 was the container for all other forms.
 
Hey aharris2693. I had the same problem. Stupid, isn't it?

Ok, here's how you get out of it. Create a module and call it modMain, with a sum called subMain. Make this your start up object, and do all your processing from there. You can open and close forms to your hearts content. Then just close the main module when you're done and the program closes.

I do all my VB6 programs like this too. It's much cleaner then having a startup form.

Hope this helps.
 
"Create a module and call it modMain, with a sum called subMain"

Sorry...

Create a module and call it modMain, with a sub called subMain.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top