My doubt is :
1] I have got many forms and MDI container. There is close button on all the forms.One of the form name is Homepage.
2]Whenever the user clicks on close button,i.e.the cross button with minimize and maximize box, The form will close but at the same time it should redirect to homepage.
3]I know to show new form ,we use
But,This is written in the code when we got button or other controls.
4]What can be done with this cross close button? How to code for this?
Should the coding to be written in page_load?
Kindly reply Soon.
Thank you :)

Recommended Answers

All 13 Replies

I wrote this code but when clicked on YES its closing the application itself.
Dim response As MsgBoxResult

 response = MsgBox("Do you want to close?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "confirm")
        If response = MsgBoxResult.Yes Then


            If response = MsgBoxResult.No Then

                e.Cancel = True
                Exit Sub
            End If
        End If

you first call for homepage then you close then current form.

If you looking to open your homepage when ALL forms are closed then you need to check if all forms are closed during the closing event of every form.

I had actually also tried first call homepage and then close current form. But ,even that din't work out.

Do you have an instance of your Homepage form open already? Are you trying to make another Homepage form to open? Please provide a little more detail. Thanks

no its not already opened

Check which is ur startup form....if ur startup form is the same as the one u r closing then it will close the complete application....

dont use the me.close or me.dispose....use Me.Hide and try....

to check ur startup form click on Project -> Projectname properties -> Application tab -> Startup form

Yea my startup form is different . I have tried the code before with me.close(),me.dispose(),me.hide().
But,none worked out.

Me.Visible = False

try this :)

poojavb Yes I had tried tat also.

Check if this helps u in any way....
Below code is written in Main form closing event

Private Sub frmMain_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim dr As Object
        If e.CloseReason = CloseReason.UserClosing Then
            dr = MsgBox("Are you sure to exit the application?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question, "Hospital Management System")
            If dr = vbYes Then
                Me.Dispose() 'close the main form
                frmLogin.Show() 'shows the login form when main form closes
                e.Cancel = False 
                e.Cancel = True
            End If
            e.Cancel = True
       End If
End Sub

Try this. It worked for my application

Dim msg As String=MessageBox.Show("Are you sure to exit" , MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If msg = vbYes Then
            e.Cancel = True
End If

Hope it helps.

No.Ur above code is not working out.

I have used this code in all my application for form_closing event.....
It works out very well for me....
I dont know y its not working for u....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.