Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

RichTextContentControl Class (2007 System)

Updated: July 2008

Represents a block of text or other types of content in a document.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

[DefaultBindingPropertyAttribute("Text")]
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class RichTextContentControl : ContentControlBase, 
	ISupportInitializeControl, ISupportInitialize

A RichTextContentControl can contain text as well as many other types of content, including tables, pictures, or other content controls. You can apply a combination of formatting and styles to text in a RichTextContentControl.

To create a document region that can only contain text, use a PlainTextContentControl.

Content Controls

The RichTextContentControl is one of eight types of content controls that you can use to design documents and templates in Microsoft Office Word. Content controls have a user interface (UI) that has controlled input like a form. You can use content controls to prevent users from editing protected sections of the document or template, and you can also bind content controls to a data source. For more information, see Content Controls.

The following code example adds a new RichTextContentControl to the beginning of the document.

This version is for a document-level customization. To use this code, paste it into the ThisDocument class in your project, and call the AddRichTextControlAtSelection method from the ThisDocument_Startup method.

private Microsoft.Office.Tools.Word.RichTextContentControl richTextControl1;

private void AddRichTextControlAtSelection()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Select();

    richTextControl1 = this.Controls.AddRichTextContentControl("richTextControl1");
    richTextControl1.PlaceholderText = "Enter your first name";
}

This version is for an application-level add-in. To use this code, paste it into the ThisAddIn class in your project, and call the AddRichTextControlAtSelection method from the ThisAddIn_Startup method.

private Microsoft.Office.Tools.Word.RichTextContentControl richTextControl1;

private void AddRichTextControlAtSelection()
{
    if (this.Application.ActiveDocument == null)
        return;

    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    vstoDoc.Paragraphs[1].Range.Select();

    richTextControl1 = vstoDoc.Controls.AddRichTextContentControl("richTextControl1");
    richTextControl1.PlaceholderText = "Enter your first name";
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft