Content Controls Sample
This sample runs only in Microsoft Office Word 2007.
This sample demonstrates how to use content controls on a Word document. The document includes a table that contains content controls in the second column, and brief descriptions for each content control in the first column. The sample also demonstrates how content controls can span page breaks.
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
In the first row of the table, verify that you cannot edit or delete the rich text control.
In the second row of the table, type a number in the plain text control.
Verify that the control accepts only numbers from 1 through 100.
In the third row of the table, click the icon in the picture control and browse to an image to display it.
In the fourth row of the table, select one of the job titles or type your own job title in the combo box control.
Verify that a warning appears if you click outside the combo box control without selecting or typing a title.
In the fifth row of the table, select one of the levels in the list.
Verify that the control does not accept values greater than 7 if the title Sales Representative is selected in the combo box control in the fourth row.
In the sixth row of the table, select a date in the date picker control.
In the last row of the table, type a street address, city, state, and zip code.
Verify that you cannot delete any of the controls that are nested in the group control.
In the rich text control after the table, insert a page break. Verify that the rich text control spans the page break.
This sample demonstrates the following concepts:
Using the following content controls in a table on a Word document:
Validating text that is entered in a content control by an end user (for example, verifying that a number is between 0 and 101). The sample does this by handling the Validating event.
Performing an action after the user clicks outside a content control. The sample does this by handling the Exiting event.
Spanning a page break in a RichTextContentControl.