Solved

VB.NET passing control to another form

Posted on 2003-11-30
9
221 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:MarcGraff
ID: 9847087
queryunload?

   - Marc
0
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

679 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