A common question is to how to show custom dialogs using the InfoPath 2007 OM. In InfoPath 2003 one could use the ShowModalDialog OM function that would take an arbitrary HTML and show it. Although you can still use the old IP2003 OM in InfoPath 2007, there is a better option if you are writing in managed code, namely WinForms!
If you are writing using IP2007 OM, you don't need to do anything special, System.Windows.Forms has already been referenced for you and the using statement has been included.
If you are writing using IP2003 OM, make sure to select "Add Reference" for your project and add System.Windows.Forms. Now you can start showing message boxes or create your custom winforms and show them when needed.
Important: you cannot use WinForms when developing for InfoPath Forms Server. This is because no .NET code can run on the client and running WinForms on the server makes little sense. If you cannot use WinForms, make sure your compatibility is not set to "Browser" in Design Checker.
Scenario 1 - Show a simple confirmation box
if (MessageBox.Show(
"Are you sure",
"Question",
MessageBoxButtons.OKCancel) == DialogResult.OK)
{ // do something
}
Note: in IP2003 OM, you will have to prefix each WinForms type with "System.Windows.Forms". You cannot simply add a "using" statement because WinForms types will clash with the IP2003 ones. However you could use aliases in your using, for example:
using WF=System.Windows.Forms;
Scenario 2 – Show a custom dialog box
Showing a custom dialog box is as simple as adding a new WinForm class to your project. Simply right-click the project in SolutionExplorer, select "Add" and then "Windows Form".
Here is source code example for a Message Box that can show/hide additional details:
http://www.infopathdev.com/files/folders/examples/entry41183.aspx
To invoke it, call the following:
new MessageBoxWithDetails(caption, message, details).ShowDialog();
MessageBoxWithDetails is good to show exception data with the stack trace going into details, for example.