Show All

# Displaying alerts and dialog boxes

When writing programming code to extend the functionality of a Microsoft Office InfoPath 2003 form, it is often useful to provide the user with information in a dialog box. Programmatically displaying a dialog box is accomplished in InfoPath by using the UI object.

Overview of the UI object

The UI object provides the following methods that form developers can use to display different types of dialog boxes to InfoPath users when they are filling out a form.

Name | Description
--- | ---
Alert method | Displays a simple message box that contains a specified message string
Confirm method | Displays a message box with buttons for input from a user. The value that is returned is one of the XdConfirmChoice enumerated constants.
SetSaveAsDialogFileName method | Sets the default file name for a form in the Save As dialog box.
SetSaveAsDialogLocation method | Sets the initial location at which the Save As dialog starts to browse when it is opened.
ShowMailItem method | Creates a new e-mail message in the default e-mail application, with the currently open form attached to the message
ShowModalDialog method | Displays a modal dialog box, based on the specified .html file and positional arguments
ShowSignatureDialog method | Displays the built-in Digital Signatures dialog box

Using the UI object

The UI object is accessed through the UI property of the XDocument object. The following example demonstrates using the ShowMailItem and Alert methods of the UI object:

    XDocument.UI.ShowMailItem("someone@example.com", "", "",
       "Updated Form", "Here is the updated form that you requested.");

    XDocument.UI.Alert("The e-mail message has been sent.");

This example demonstrates how to use the ShowModalDialog method of the UI object to display a custom dialog box:

    function Import()
    {
       // Show a modal dialog with a size of 400x600 and using Import.htm for
       // its contents.  The XDocument object is passed as a dialog parameter
       // and the number of CDs which were imported is returned.
       var intImported = XDocument.UI.ShowModalDialog("Import.htm",
          XDocument, 400, 600);

       // Display how many CDs were imported.
       if (intImported > 1)
          XDocument.UI.Alert(intImported + " CDs were imported.");
       else if (intImported == 1)
          XDocument.UI.Alert(intImported + " CD was imported.");
    }

For more information about how the methods of the UI object are used, click the methods in the preceding table.

©2003-2004 Microsoft Corporation. All rights reserved. Permission to copy, display and distribute this document is available at: http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp