Search code examples
c#.netwpfmessagebox

Is it possible to catch MessageBox closing?


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?


Solution

  • 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.