Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTO Addin Dialog Box

Tags:

c#

I have a dialog box popup in a VSTO addin for outlook 2013. I test for DialogResult.Yes and No, to which I have set the two buttons' results. They work fine, but I want yet another behavior when the user cancels out of the box. When they press cancel the code just continues. Is there something I can call to stop the addin from executing if they cancel the dialog box? How can I test for the cancel button? I tried res == DialogResult.Cancel but it can't cast res to bool and it's type DialogResult because I also test for Yes and No.

How can I tell if they press the cancel button, and how can I exit the addin. In python the command would be sys.exit() What is the C# equivalent?

like image 913
ss7 Avatar asked Mar 15 '23 22:03

ss7


1 Answers

If you use the System.Windows.Forms.MessageBox class for displaying dialog boxes in the add-in you may use the following code for checking the chosen option:

// Display message box
DialogResult result = MessageBox.Show(messageBoxText, caption, button, icon);

// Process message box results 
switch (result)
{
    case MessageBoxResult.Yes:
        // User pressed Yes button 
        // ... 
        break;
    case MessageBoxResult.No:
        // User pressed No button 
        // ... 
        break;
    case MessageBoxResult.Cancel:
        // User pressed Cancel button 
        // ... 
        break;
 } 

See Dialog Boxes Overview in MSDN for more information.

If you developed your own window you may add an event handler for the button's Click event.

like image 169
Eugene Astafiev Avatar answered Mar 23 '23 16:03

Eugene Astafiev