• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2011
  • Last Modified:

How to load a MDI form from a Login form

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
  • 2
1 Solution
Bob LearnedCommented:
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.

Mike TomlinsonMiddle School Assistant TeacherCommented:
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.
ananmananAuthor Commented:
I'm using 2005. I'm not very clear how to do it. Can u please guide me to do it.
Mike TomlinsonMiddle School Assistant TeacherCommented:
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.

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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now