Word Add-In Dynamic Controls Sample
Note
This sample runs only in Microsoft Office Word 2007.
When you do not know at design time how many controls will be required in a document at run time, you can add controls dynamically in response to events.
This sample demonstrates how to add and remove Windows Forms controls and host controls at run time.
Security Note: |
---|
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties. |
To run this sample
Press F5.
Click inside the document.
Select a check box in the task pane.
A control is added at the cursor location.
Clear the check box that you selected.
The control is removed from the document.
Controls created by add-ins are not saved automatically in the document. This sample saves the control information to a custom XML part so that the controls can persist between Word instances.
To save the controls
Press F5.
Click inside the document.
Select a check box in the task pane.
A control is added at the cursor location.
Click the Save button.
The Delete controls dialog box appears.
Click No.
In the Save As dialog box, type a file name for this worksheet, and click Save.
Exit Word.
Open the file that you just saved.
The controls are still present in your document.
Demonstrates
Dynamically placing Windows Forms controls and host controls on a document.
Dynamically removing Windows Forms controls and host controls from a document.
Storing host control information in an XML part that is saved as part of the document.
See Also
Tasks
Excel Add-In Dynamic Controls Sample
Concepts
Host Items and Host Controls Overview
Other Resources
Change History
Date |
History |
Reason |
---|---|---|
July 2008 |
Added topic. |
SP1 feature change. |