1

I've been trying to figure out the correct way to pop up a dialog box in a way similar to MessageBox.Show in my VSTO addin. I read this could be achieved using WPF, but is there a better way? I've found many different examples most of which are in VBA, but I'm using C# so I'm having trouble translating them over. If someone could provide me with an example of popping up a dialog box in the addin in order to collect some information from the user, and point me towards the correct docs to tweak the settings of the dialog box it would help a lot. I can't seem to get it to work in C# using the VBA examples and as for the docs I can't find ones pertaining to dialog boxes in VSTO, just outside of it in WPF which I am not sure is possible to use in this situation.

Any assistance would be most appreicated. I just want to display a dialog box, and collect some info and that's it. I know of dialog launcher for VSTO ribbon groups, but that is not what I need.

Thanks in advance.

ss7
  • 2,902
  • 7
  • 41
  • 90

1 Answers1

3

You can use a regular System.Windows.Forms.Form instance to display a dialog window for collecting the required information. Use ShowDialog method which shows the form as a modal dialog box with the specified owner. Don't forget to psecify the parent window handle to prevent any changes in Outlook. The IWin32Window interface provides an interface to expose Win32 HWND handles to the ShowDialog method.

If you need to diaplay a WPF contant you may use the ElementHost class. This is a Windows Forms control that can be used to host a Windows Presentation Foundation (WPF) element.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Thanks this was a huge help. – ss7 May 08 '15 at 15:35
  • I found an example of getting the parent handle and passing it in. I can't seem to locate it now. Can you provide a small example of doing so and then initializating/calling the form/showdialog method? – ss7 May 09 '15 at 03:11
  • http://stackoverflow.com/questions/6748544/popup-dialog-box-in-word-addin Here is an example I found. I think it's mostly correct. Can you help me out and let me know what should be changed? I also assume I can place this in my ThisAddIn_Startup method? – ss7 May 09 '15 at 03:19
  • 1
    You are on the right avenue. Need to create an instance of the IWin32Window interface and pass it to the Show method of the Form class. What code do you have now? – Eugene Astafiev May 09 '15 at 17:05
  • 1
    You need to run that code in the event hander where you need to Show the form instance. – Eugene Astafiev May 09 '15 at 17:05