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 7062367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:35:08+00:00 2026-05-28T04:35:08+00:00

Within the application I am writing for testing/learning C#, I use the hidden/visible property

  • 0

Within the application I am writing for testing/learning C#, I use the hidden/visible property to open and close windows.
It is a WPF application.

In the main window, I have a “close” button that triggers this method:

public void buttonQuit_Click(object sender, RoutedEventArgs e)
{
    var message = exitmessage;
    var title = exitTitle;
    var result = MessageBox.Show(
        message,                    // the message to show
        title,                      // the title for the dialog box
        MessageBoxButton.YesNo,     // show two buttons: Yes and No
        MessageBoxImage.Question);  // show a question mark icon

    // lets see what has been pressed
    switch (result)
    {

        case System.Windows.MessageBoxResult.Yes:   // Yes button pressed
            CloseAllWindows();
            break;

        case System.Windows.MessageBoxResult.No:    // No button pressed
            break;

        default:                 // Neither Yes nor No pressed (just in case)
            MessageBox.Show("Oh noes! What did you press?!?!");
            break;
    }
}

This way I make sure that all windows get closed, including the hidden ones.
But now is the catch; when the user presses (in the main window) the top right red X in toolbar to close, only that main window gets closed, but in the background the hidden ones are still there.

So in fact it is 2 questions:

  1. Is CloseAllWindows(); really sufficient to get the app 100% closed down?

  2. How do I “catch” the event when the user presses that red X in the toolbar, and make this also trigger the right closing event?

  • 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-28T04:35:08+00:00Added an answer on May 28, 2026 at 4:35 am

    You should be handling either the Closing or Closed event for your window(s). The former allows you to cancel the close, while the latter just allows you to perform necessary cleanup in response to the window being closed.

    So, in this case, you should place the code from your buttonQuit_Click method into a handler method attached to the Closing event so that it gets triggered regardless of how the window is closed.

    Then, your buttonQuit_Click method can simply call the window’s Close method. That will close the window, in turn raising the Closing event, and running your code in the attached handler method.

    As far as your other question, CloseAllWindows will do exactly what it says: it will close all of the windows that your application has opened. In most cases, that should be sufficient to close the application, but it might not be, especially if you’ve created non-background threads or depending on the ShutdownMode setting.

    App.Current.Shutdown will work unconditionally.

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

Sidebar

Related Questions

So I am writing a web application for use within my organization. The application
I'm currently writing an Android application which needs to use OCR within it. To
I'm writing a ASP.NET application used within our company. Now I want to send
I'm writing an application which reads and displays images as ImageIcons (within a JLabel),
Within my application, I use the MiniDumpWriteDump function (see dbghelp.dll) to write a crash
I was writing a simple test application. There are two radio buttons within the
I'm writing an NUnit TextFixture for portions of a Windows Forms application. Some of
I'm writing an application to receive SMS messages via an HTTP gateway. The main
I'm writing an application that will need to reboot the Windows machine the code
I'm writing an application, The main purpose of the application is to be able

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.