Solved

VB.NET passing control to another form

Posted on 2003-11-30
9
215 Views
Last Modified: 2006-11-17
I am new at .net so bare with me...

I have a login form where the user puts in the user name and password then I want it to open a menu form.

The problem is when I close the login form the application closes. Is there a way to pass off the control?

I am currently useing this:
            Dim objForm As New FrmMenu()
            objForm.Show()
            objForm.Visible = True

But I am up for any suggestion!

   Thanks,
     - Marc
0
Comment
Question by:MarcGraff
  • 5
  • 4
9 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 9846948
Hi MarcGraff,
After objForm.Show I suggest you try:

Me.Hide

Dabas
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 9847064
then how would the application terminate when the menu form is closed? currently it just sits in memory.

   - Marc
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9847078
MarcGraff,
The correct way to do this probably is to set the startup object to Sub Main
You create sub main in a module.

In this module, you call the login form as a dialog box, and once it exits from there, you call the menu form.
You can program the queryunload event of this last form to close the application properly

Dabas
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 9847087
queryunload?

   - Marc
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:MarcGraff
ID: 9847148
Asuming you are refering to Handles MyBase.Closed,

How would I close the Login Form from the Menu Form

or

How do I stop the application from emedietly ending when useing submain
        Sub Main()
            Dim Login As New FrmLogin()
            Login.Show()
        End Sub

   - Marc
0
 
LVL 27

Accepted Solution

by:
Dabas earned 500 total points
ID: 9847235
MarcGraff,
        Sub Main()
            Dim Login As New FrmLogin(), objForm As New FrmMenu()
            Login.ShowDialog() 'This will bring up Login modally.
            objForm.Show 'This will bring up the menu form. Sub Main will end after showing
        End Sub
Forget my QueryUnload remark. I thought .NET behaves like VB6

You can use Mybase.Closing to handle the cleanup and proper exit from your code.
If you are lazy, you can use the End statement and let .NET do the dirty work for you

Dabas
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 9847273
           Dim Login As New FrmLogin()
            Dim objForm As New FrmMenu()

            Login.ShowDialog()  ' works great
            objForm.Show() ' FrmMenu shows but closes emedietly and the app ends :(

I tryed: objForm.ShowDialog()
and it works... Should I not do this?

   - Marc
 
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9847293
MarcGraff,
It will also work.
You will understand exactly what happens if you single step through the code as I wrote it:

You will see that after Login.ShowDialog, the Login form comes up, but Sub Main waits for you to close it before proceeding with the next line.
After objForm.Show, the menu form will show up, but Sub Main will continue with End Sub, thereby removing itself from memory.



Dabas
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 9847308
Thanks so much!

   - Marc
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now