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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:04:27+00:00 2026-05-15T15:04:27+00:00

I have a form in a Windows form application that I want to display

  • 0

I have a form in a Windows form application that I want to display on top of a main form, close it, and then immediately show a dialog box using MessageBox.Show(). But the first form is still showing when the message box is shown, and it does not disappear until I click OK on the message box. I tried waiting to show the message box in an event handler for the form’s VisibleChanged event and even calling Refresh() on both the form and the main form. Is there a way I can determine when the first form has fully disappeared before displaying the message box?

Edit:

Here is some code that demonstrates how the forms are being shown.

static class Program
{
    // The main form is shown like this:
    static void Main()
    {
        Application.Run(new MainForm());
    }
}

public class Class1 
{
    // _modalForm is the first form that is displayed that won't fully go away 
    // when it is closed.
    ModalForm _modalForm;
    BackgroundWorker _worker;

    public Class1()
    {
        _modalForm = new ModalForm();
        _worker = new BackGroundWorker();
        _worker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted
    }

    public void Method1()
    {
        _worker.RunWorkerAsync();

        // The first form is shown.
        _modalForm.ShowDialog();
    }


    // This code runs in the UI thread.         
    void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        _modalForm.VisibleChanged += new EventHandler(_modalForm_visibleChanged);
        _modalForm.Close();
    }

    void _modalForm_visibleChanged(object sender, EventArgs e)
    {
        // When the message box is shown, the other form is still visible
        // and remains so until I click OK.
        MessageBox.Show("The other form was just closed.");

        // Note:  I originally tried to use the FormClosed event instead of
        // VisibleChanged.  Then I tried Deactivate, in attempt to use an event
        // that occurred later thinking that might do the trick.  VisibleChanged
        // is the latest event that I found.
        // 
    }
  • 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-15T15:04:28+00:00Added an answer on May 15, 2026 at 3:04 pm

    I’ll guess that you are running your code on Windows XP or Vista/Win7 with Aero turned off. Closing a form does not make the pixels on the screen disappear instantly. The Windows window manager sees that the window for the form got destroyed and that this revealed parts of other windows underneath it. It will deliver a WM_PAINT message to let them know that they need to repaint the parts of the window that got revealed.

    This will not work properly if one or more of those windows isn’t actively pumping a message loop. They can’t see the WM_PAINT message. They won’t repaint themselves, the pixels of the closed form will remain on the screen.

    Find out why these windows are not responding. Hopefully it is your window and the debugger can show you what the UI thread is doing. Make sure it isn’t blocking on something or stuck in a loop.


    After seeing the edit: there’s indeed blocking going on, of a different kind. The MessageBox.Show() call is modal, it prevents the VisibleChanged event from completing. That delays the closing of the form.

    Use System.Diagnostics.Debug.WriteLine() or Console.WriteLine() to get diagnostics in a Window Forms app. You’ll see it in the Output window. Or simply use a debugger breakpoint.

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

Sidebar

Related Questions

I have a combo box in a C# Windows form application that is being
I have a windows form application that uses a Shared class to house all
I have a Windows form application that's consuming web services over https and is
I have a C# Windows Form application that contains a menu with this event:
I have a Windows application that has 2 Forms . From one form I
I am using windows application and I have four combo boxes(comboeventname,combosendtype,comboType,comboschedule) in that form....
I'm working on a windows form application and I want to have a rich
I have a Windows Form application that involves two Forms. The child form is
In my WPF application, I have a ListView on the main form that displays
I have a Windows Form application built on a data model and a Windows

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.