-
Hi, i want to create a MDIform with an MDI child form in it, in which the user can only close the MDI child through closing the MDIform, but not to click the (X) button on the MDI child form. "I've tried to disable the X button for the child form, but when i Maximized the form i can still close the form."
-
Cancel the Unload
You can put a little check in the QueryUnload event of the child form, to check how the form is closing down. If it's not because the parent is unloading, then you can cancel the unload. This has the effect of disableing all ways of closing the form, except the way you want.
The QueryUnload event has an argument called UnloadMode. The values that this argument may have are:
vbFormControlMenu - Closing with Alt+F4, or the little close button
vbFormCode - closing because you are unloading it in your coding.
vbAppWindows - closing because Windows is shutting down
vbAppTaskManager - Being closed from task manager
vbFormMDIForm - closing because the MDI parent form is closing
vbFormOwner - closing because the owner form is closing.
Code:
'This form will only close if the MDI parent closes,
'or if I close it from my coding.
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode <> vbFormMDIForm And UnloadMode <> vbFormCode Then
Cancel = True
End If
End Sub
Hope this Helps.
Shrog