Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 609429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:33:58+00:00 2026-05-13T17:33:58+00:00

The problem : A dialog’s FormClosing() event is raised if it’s a child, ie

  • 0

The problem: A dialog’s FormClosing() event is raised if it’s a child, ie it’s Owner property is set to the parent form, but NOT if it’s a child-of-a-child. So closing the main form does not call the closing event on any grandchildren dialogs.

The Details: A dialog prompts to “Save Changes?”, with YesNoCancel buttons, in the FormClosing() event. Clicking Cancel keeps the dialog open, ie cancel closing.

Private Sub Dialog_FormClosing(...) Handles Me.FormClosing
    If MessageBox.Show("Save Changes?", YesNoCancel) = No Then
        e.Cancel = True
    End If
End Sub

So instantiating a new dialog, with its Owner property set…

// called from the main form
Dim dlg As New Dialog
dlg.Owner = Me
dlg.Show()

… has the benefit that the dialog will prompt to save if the user tries closing the owner/parent. Clicking Cancel will keep the dialog open, and it’s owner as well.

But if that same dialog was shown from a child of a parent (also with it’s owner property set), and not from a parent:

// called from another child 
Dim dlg As New Dialog
dlg.Owner = Me
dlg.Show()

Then the FormClosing() event on the child does not raise, if the top-most parent is closed.

Is this a know design limitation in the framework? Is there anything I should consider before I start hacking a nasty solution for this?

Thanks for any replies.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:33:58+00:00Added an answer on May 13, 2026 at 5:33 pm

    Yes. Part of the problem is that you talk about them as dialogs but don’t actually use the ShowDialog() method to display them. That would make it impossible for the user to close the main form while a dialog is displayed. The message loop terminates when the main form is closed, the remaining forms will be disposed without going through the normal shutdown sequence.

    One solution is to pro-actively close the forms yourself when the main form closes. This worked well:

      Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        For frm As Integer = Application.OpenForms.Count - 1 To 1 Step -1
          Application.OpenForms(frm).Close()
          If Application.OpenForms.Count - 1 = frm Then
            e.Cancel = True
            Exit For
          End If
        Next
      End Sub
    

    You probably should pay attention to e.CloseReason so you don’t block a Windows shutdown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem: I open the dialog, open the SIP keyboard to
I have a problem with the jquery-ui dialog box . The problem is that
I have to write an applet that brings up a password dialog. The problem
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem: I have an address field from an Access database which has been converted
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
Problem: Ajax suggest-search on [ n ] ingredients in recipes. That is: match recipes
Problem: Given a list of strings, find the substring which, if subtracted from the
Problem is described and demonstrated on the following links: Paul Stovell WPF: Blurry Text
Problem Language: C# 2.0 or later I would like to register context handlers to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.