0
votes

I have a mdi parent form which when open may have 4+ child windows open everything is operating great except the Close function - I have a confirmation window show as follows

Private Sub index_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    If MessageBox.Show("Are you sure you want to exit?", "prompt", MessageBoxButtons.YesNo) = DialogResult.Yes Then
        'allow close
    Else
        e.Cancel = True
    End If
End Sub

this is working appropriately EXCEPT when you click no while the mdi parent remains open the child forms all close. How do I prevent this?

Images to help:

Normal operation http://fasttrackdispatch.com/design/normalop.png

but when you click x and it brings up the prompt message which looks like this (notice for some reason all mdi child elements closed - I did not code for this to happen) http://fasttrackdispatch.com/design/exitmenu.png When you click no the mdi children do not return http://fasttrackdispatch.com/design/exitmenuno.png

the question is why are the mdi children closing and how can we prevent it?

1
I cant quite understand the last sentence, it is all run on. If they say Yes, they want to exit, you dont have to call App Exit. It is already exiting, so just let it do so by not cancelling.Ňɏssa Pøngjǣrdenlarp
edited to clarify; this is referencing when the user changes their mind and clicks no - (yes is successfully closing appropriately), clicking no causes all windows inside the parent to closeJames Stafford

1 Answers

1
votes

You could handle the FormClosing event of the child form(s) and, if e.CloseReason is MdiFormClosing, you can then prompt the user to confirm before the child form(s) is closed.