Share via


Working with form windows

When working programmatically with a Microsoft Office InfoPath 2003 form, you can write scripting code to access the form's windows, and then customize some of the items that they contain. The InfoPath object model supports access to a form's windows through the use of the Window object in association with the Windows collection.

There are two types of windows in an InfoPath form: the editing window that is used as the form area when a user fills out a form, and the designing window that is used as the design mode when a user designs a form. When writing scripting code in a form, it is the editing window that provides the most useful functionality, because you can use the Window object associated with it to access a variety of properties and methods that can be used to customize a form.

Overview of the Windows collection

The Windows collection provides the following properties that form developers can use to manage the Window objects that it contains.

Name Description
Count property Returns a count of the number of Window objects contained in the collection
Item property Returns a reference to the specified Window object

Overview of the Window object

The Window object provides the following methods and properties that form developers can use to interact with an InfoPath window.

Name Description
Activate method Designates the window as the currently active window
Active property Returns a Boolean value indicating whether the window is the currently active window
Caption Property (Window Object) property A read/write property that returns or sets the caption text for the window represented by the Window object
Close method Closes a window
CommandBars property Returns a reference to the Microsoft Office CommandBars object
Height property A read/write property of type long integer that specifies the height of the the window represented by the Window object, measured in points
Left property A read/write property of type long integer that specifies the horizontal position of the window represented by the Window object, measured in points
MailEnvelope property Returns a reference to the MailEnvelope object
TaskPanes property Returns a reference to the TaskPanes collection
Top property A read/write property of type long integer that specifies the vertical position of the window represented by the Window object, measured in points
Type property Returns a number indicating the type of the window, based on the XdWindowType enumeration
Width property A read/write property of type long integer that specifies the width of the window represented by the Window object, measured in points
WindowState A read/write property of type XdWindowState that returns or sets the state of the window represented by the Window object
XDocument property Returns a reference to the XDocument object associated with the window

Using the Windows collection and the Window object

The Windows collection is accessed through the Windows property of the Application object. When using the Windows collection to access a form's windows, you pass a long integer to the Item method to return a reference to a Window object. For example, the following code sets a reference to the first Window object contained in the Windows collection:

var objWindow;
objWindow = Application.Windows(0);

However, you can access the currently open window directly by using the ActiveWindow property of the Application object, without going through the Windows collection, as the following code demonstrates:

var objWindow;
objWindow = Application.ActiveWindow;

A Window object can also be accessed by using the Window property of the View object, which is associated with the form's underlying XML document. The View property of the XDocument object is used to access the View object. For example, the following code sets a reference to the Window object that is associated with the view of a form's underlying XML document:

var objWindow;
objWindow = XDocument.View.Window;

Note  Some of the properties and methods of the Window object are used only for the editing window type; if used with the designing window type, they will return an error.