Results 1 to 2 of 2

Thread: MDI With MDI-child form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    Garden Grove, CA, USA
    Posts
    110
    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."
    ngphuocthinh

  2. #2
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186

    Smile 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width