Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: CrAz3D on August 31, 2003, 01:21 PM

Title: Form_Unload Cancel Prop
Post by: CrAz3D on August 31, 2003, 01:21 PM
vb6
I am trying to get the form to not close when I click the 'close' button.  I have accomplished this by using Cancel=1

The only problem I am having is that the form I don't want to close is a MDIChild, & it will not close when I try to close the main MDI form.  Any ideas?

Title: Re:Form_Unload Cancel Prop
Post by: Skywing on August 31, 2003, 01:33 PM
Maybe you could set a flag in Form_Unload or whatever for your main window, and check that flag in Form_Unload for your MDIClient to determine whether or not it should allow itself to be closed?
Title: Re:Form_Unload Cancel Prop
Post by: CrAz3D on August 31, 2003, 01:41 PM
okey dokey, thank ya, I'lls ee what that does.
---
Well, I tried this:
If UnloadCancel = False Then
   Cancel = 1
End If
It didn't seem to work.  Any other ideas?
Title: Re:Form_Unload Cancel Prop
Post by: Grok on August 31, 2003, 02:19 PM
Use Query_Unload instead.  It provides the mechanism you need to decide the reason why the form is closing.  If the reason is the system menu (user clicked) then set Cancel = True.  For all other reasons, set Cancel = False.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   Select Case UnloadMode
   Case vbFormControlMenu  '0 The user chose the Close command from the Control menu on the form.
       Cancel = True
   Case vbFormCode         '1 The Unload statement is invoked from code.
   Case vbAppWindows       '2 The current Microsoft Windows operating environment session is ending.
   Case vbAppTaskManager   '3 The Microsoft Windows Task Manager is closing the application.
   Case vbFormMDIForm      '4 An MDI child form is closing because the MDI form is closing.
   Case vbFormOwner        '5 A form is closing because its owner is closing
   End Select
End Sub
Title: Re:Form_Unload Cancel Prop
Post by: CrAz3D on August 31, 2003, 02:35 PM
Thank ya kindly

EXTREMELY KINDLY!  ;D