Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.NET passing control to another form

Posted on 2003-11-30
9
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

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!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

715 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