Solved

VB.NET passing control to another form

Posted on 2003-11-30
9
225 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

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.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

623 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