How to load a MDI form from a Login form

Posted on 2007-08-06
Last Modified: 2013-11-05
I need to how do I show a MDI form from the Login screen.

I have tried with this code. But its not working.

                Dim MDIMain As New Form
                MDIMain.MdiParent = Me

and I have tried this one also.
                Dim MDIMain As New Form
                ''MDIMain.MdiParent = Me

Its not working. Please help me
Question by:ananmanan
    LVL 96

    Expert Comment

    by:Bob Learned
    You could set the startup object to Sub Main, and show the Login form modally, and get the DialogResult from the form before showing the main form.

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    What version VB.Net?

    If 2003 (or below) then do it Bob's way.

    If 2005 then leave the MdiForm as the Startup Object and use the Application.Startup() event to show your login form as a Dialog.  If login fails than set the e.Cancel property to true to cancel the loading of the application.
    LVL 1

    Author Comment

    I'm using 2005. I'm not very clear how to do it. Can u please guide me to do it.
    LVL 85

    Accepted Solution

    Click on Project --> Properties and click on the "View Application Events" button in the bottom right.

    Now, across the top of the code editor are two dropdowns.
    Change the left dropdown from "(General)", to "(MyApplication Events)".
    Next change the right dropdown from "(Declarations)", to "Startup".

    Add some code to the autogenerated event so it looks something like this:

            Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
                Dim fl As New frmLogin
                If fl.ShowDialog <> DialogResult.OK Then
                    e.Cancel = True ' cause app to close
                End If
                ' otherwise, app continues loading whatever Form the "Startup Object" is set too...
            End Sub

    Finally, in "frmLogin", you need to set the DialogResult property of that form (at run-time via code of course!) to indicate whether login was sucessful or not.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    I'm currently working for a company where I have to upgrade over 50 VB6 programs to VB.NET 2008.  So far I'm about half way through, and I've learned quite a few tricks that drastically improve the performance of VB.NET apps. Because there are a…
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    18 Experts available now in Live!

    Get 1:1 Help Now