Adding an InfoPath Editor Control to a Windows Form

One of the new features of InfoPath 2007 is the ability to integrate the InfoPath editor into Windows Forms. Within Visual Studio this is done using the Microsoft.InfoPath.FormControl.dll assembly. In this example using Visual Studio 2008, we will create a simple Windows Form application that contains the InfoPath control.

Note: This example assumes that you have created a Windows Form Project

Add the InfoPath Form Control to the Toolbox

1. In the general section of the toolbox right click and select Choose Items

2. In the Choose Toolbox Items dialog select browse

3. Add the reference to the Microsoft.Office.InfoPath.FormControl.dll which by default is in the C:\Program Files\Microsoft Office\Office12

4. Once the reference is added the Choose Toolbox Items contains the reference.

5. The control is now available in the General section

Once the FormControl is added to the toolbox drag it onto the Windows Form.

Write the code

 

Loading an InfoPath Form Template (.xsn) can be done using the NewFromFormTemplate method of the FormControl object. As an example of this add the following code to the button.

 

Run the completed application and select the Load Form button to see the InfoPath form.