Поделиться через


DocumentBase.SelectContentControlsByTitle Method

Returns all the content controls in the document that have the specified title.

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

Syntax

'Declaration
Public Function SelectContentControlsByTitle ( _
    title As String _
) As ContentControls
public ContentControls SelectContentControlsByTitle(
    string title
)

Parameters

  • title
    Type: System.String
    The title of the content controls to return.

Return Value

Type: Microsoft.Office.Interop.Word.ContentControls
A ContentControls collection that contains the content controls that have the specified title.

Examples

The following code example adds two paragraphs to the document and then adds one control to each new paragraph: a RichTextContentControl, and a ComboBoxContentControl. The example sets the Tag and Title properties of each control. Next, the code calls the SelectContentControlsByTitle method to get the collection of native content controls whose title equals Customer Title. It then modifies the placeholder text of each control in the returned collection, which in this case contains only the ComboBoxContentControl. To use this example, run it from the ThisDocument class in a document-level project.

Private Sub ContentControlsTitle()
    Dim par1 As Word.Paragraph = Me.Paragraphs.Add()
    Dim richTextControl As Microsoft.Office.Tools.Word.RichTextContentControl _
        = Me.Controls.AddRichTextContentControl(par1.Range, "richTextControl")
    richTextControl.Tag = "Customer"
    richTextControl.Title = "Customer Name"

    Dim par2 As Word.Paragraph = Me.Paragraphs.Add()
    Dim comboBoxControl As Microsoft.Office.Tools.Word.ComboBoxContentControl _
        = Me.Controls.AddComboBoxContentControl(par2.Range, "comboBoxControl")
    comboBoxControl.Tag = "Customer"
    comboBoxControl.Title = "Customer Title"

    Dim myControls As Word.ContentControls = _
        Me.SelectContentControlsByTitle("Customer Title")
    For Each ctrl As Word.ContentControl In myControls
        ctrl.SetPlaceholderText(Text:="Select a title.")
    Next
End Sub
private void ContentControlsTitle()
{                        
    Word.Paragraph par1 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.RichTextContentControl richTextControl = 
        this.Controls.AddRichTextContentControl(par1.Range, 
        "richTextControl");
    richTextControl.Tag = "Customer";
    richTextControl.Title = "Customer Name";

    Word.Paragraph par2 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl = 
        this.Controls.AddComboBoxContentControl(par2.Range, 
        "comboBoxControl");
    comboBoxControl.Tag = "Customer";
    comboBoxControl.Title = "Customer Title";

    Word.ContentControls myControls = 
        this.SelectContentControlsByTitle("Customer Title");
    foreach (Word.ContentControl ctrl in myControls)
    {                                
        ctrl.SetPlaceholderText(null, null, "Select a title.");                
    }
}

.NET Framework Security

See Also

Reference

DocumentBase Class

Microsoft.Office.Tools.Word Namespace