Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a couple of form and i use one form as mdiparent. i add command to unabled close if there's mdichildren active. i put it on mdiparent private sub form_closed. it work on exit menu strip and close button (x). but it not take any effect when we use Alt+F4 key. where should i put the command?

VB
If MdiChildren.Count > 0 Then
            MessageBox.Show("Close All Form!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            e.Cancel = True
        Else
            If MdiChildren.Count = 0 And MessageBox.Show("You Want To Close Your Program?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.No Then
                e.Cancel = True
            Else
                e.Cancel = False
            End If
        End If
Posted
Comments
Sergey Alexandrovich Kryukov 24-Feb-15 23:12pm    
Listen to a good friendly advice: never use MDI, don't scare off your users.
Okay, you screwed up Alt+F4, but you didn't show where.
—SA
vendir 24-Feb-15 23:17pm    
so what should i use?
when i hit Alt+F4 even when there's mdichildren active, it will close all form without asking to close all form

1 solution

In order to verify the close operation and to be able to cancel it, place the code in Closing[^] method.
 
Share this answer
 
Comments
vendir 25-Feb-15 0:08am    
i add the command on form closing it happen just the same
Wendelius 25-Feb-15 0:49am    
Did you set Cancel to true? See CancelEventArgs.Cancel[^]
vendir 25-Feb-15 23:43pm    
it happen same actually. alt+f4 still work when there's mdichildren active. sorry i'm really a rookie on this. can you please explain? thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900