Question

Is there any way for detect MessageBox closing. Some workarounds can be possible maybe I can write my own custom MessageBox, but I want the operating system's MessageBox.

Maybe something like MessageBox.Closing += new EventHandler, any suggestions?

Was it helpful?

Solution 2

You can use the MessageBox found int Extended WPF Toolkit™ Community Edition.

In its documentation there are two events called

CloseButtonClicked 
Closed

But as explained in the Tigran answer, the MessageBox.Show call is modal and block the thread in which you make the call, so there is no need to catch the close event unless you are running another thread that should react immediately in some way to the closing of the messagebox.

OTHER TIPS

There is no "normal" way of doing that, if not using some not very riliable API calls and sniffing. But according to yuor comment, you need may be something like:

var flag = true; 
MessageBox.Show(...); 
flag = false;

This is a correct way of doing that. MessageBox.Show(...); is a blocking call.

If you need more control, define your own form, and it wil become your message box. So you can have full control over it, and have also Closing event handler possibility.

In my case I just wanted to see if the MessageBox was clicked and then do something, hope it helps.

DialogResult result = MessageBox.Show("Your message");

    if (result == DialogResult.OK)
    {
        Application.Exit(); //whatever you want
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top