Solved

VB.NET passing control to another form

Posted on 2003-11-30
9
222 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding to a VBA? 6 94
Run code from text file in vb 1 103
Spell Check in VB6 13 152
Export PDF Form fields to Access  or Excel  in Tab order 16 129
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

752 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