Windows Develop Bookmark and Share   
 index > Windows Forms Designer > My Mdi Parent is not opening
 

My Mdi Parent is not opening

Hi,

I have awindows project developed in vs2008.I have to login to show the Mdi form of the project.

I have kept the starting point of my project to Login.vb page.

Here i enter userid and password andlogin.

After successful login i have to show the Mdi form.

Dim sUserName As String, sPassword As String, pstatus As String
        Dim nUserID As Integer, nUsername As String
//creating the mdi here 
        
Dim mdiform As New MDIparent()
        Dim cnn As SqlClient.SqlConnection = New SqlClient.SqlConnection(My.Settings.connectionstring)
        Dim adapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter
        Dim dt As New DataTable, strSQL As String

        Try
            sUserName = txtUserName.Text.Trim
            sPassword = txtPassword.Text.Trim

            If sUserName.Length = 0 Then
                MsgBox("You must enter a user name")
                txtUserName.Focus()
            ElseIf sPassword.Length = 0 Then
                MsgBox("You must enter a password")
                txtPassword.Focus()
            End If

            //code for login goes here 

                If pstatus = True Then
                    txtUserName.Focus()
                Else
                    My.Settings.UserID = nUserID
                    My.Settings.Username = sUserName
                    mdiform.Show()
                    Me.Close()
                End If
            Else
                MsgBox("Invalid username or password. Please try again")
                txtUserName.Focus()
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Login Error")
            txtUserName.Focus()
        End Try
        txtUserName.Text = ""
        txtPassword.Text = ""
    End Sub
Once ilogin using the login credentials i have to close the login form and show the mdi parent. But the applicationwill quit once it is logged in.

Any suggestions.

manojbavikati  Thursday, July 30, 2009 3:30 PM
Hello Manoj

Most probably the reason of closing of application is that you have set the shutdown mode of the application to "When Startup form Closes". Change this to "When Last Form Closes".

You can do this in your project properties ->Application

Another way to solve your problem is to use application events. you can set the startup form to the MDI form and show the login form in the Application_Startup event. if the login is successfull then continue which will load the mdi and in case of login failure you can close your application in the startup event itself.
Happy Debugging Bimal
Bimal.net  Tuesday, August 04, 2009 10:04 AM
Hi ,

Use the Dialog Form as login form and set DialogResult Ok ,Cancel and modify the above code little a bit as given below

//code for login goes here 

After successful login the Login Dialog Form return Ok , in either case it will return Cancel
//If the login is successfull open the mdi from 
 if(loginform.ShowDialog() == DialogResult.Ok)
  
	           My.Settings.UserID = nUserID
                   My.Settings.Username = sUserName
                   mdiform.Show()
ELSE
// If user click on Cancel exit form application
 Application.Exit(0);

            
Malik M.Shahid  Tuesday, August 04, 2009 9:45 AM
Hello Manoj

Most probably the reason of closing of application is that you have set the shutdown mode of the application to "When Startup form Closes". Change this to "When Last Form Closes".

You can do this in your project properties ->Application

Another way to solve your problem is to use application events. you can set the startup form to the MDI form and show the login form in the Application_Startup event. if the login is successfull then continue which will load the mdi and in case of login failure you can close your application in the startup event itself.
Happy Debugging Bimal
Bimal.net  Tuesday, August 04, 2009 10:04 AM

You can use google to search for other answers

Custom Search

More Threads

• I can't seem to control the AutoSize's initial value of a label-derived control
• Problem with Windows Forms designer when assembly loads another assembly using reflection
• Short cut to find a control in the designer
• How to Change the settings of an application with User.config
• DataMember property not found
• Regarding Toolbox images
• Browse the Hard Disk and get path of a folder in Vb.Net 2005?
• Relating Combos on Windows Forms
• update other form
• Alter GridSize for DesignSurface