DocumentBase.SelectContentControlsByTitle 方法

返回文档中具有指定标题的所有内容控件。

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word.v4.0.Utilities(在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

语法

声明
Public Function SelectContentControlsByTitle ( _
    title As String _
) As ContentControls
public ContentControls SelectContentControlsByTitle(
    string title
)

参数

  • title
    类型:System.String
    要返回的内容控件的标题。

返回值

类型:Microsoft.Office.Interop.Word.ContentControls
一个 ContentControls 集合,包含文档中具有指定标题的内容控件。

示例

下面的代码示例将在文档中添加两个段落,然后分别向每个新段落添加一个控件:RichTextContentControlComboBoxContentControl。 该示例还将设置每个控件的“Tag”和“Title”属性。 接下来,该代码将调用 SelectContentControlsByTitle 方法,以获取标题等于客户标题的本机内容控件的集合。 随后,该代码将修改所返回集合中的每个控件的占位符文本。在本示例中,返回的集合只包含 ComboBoxContentControl。 若要使用此示例,请从文档级项目内的 ThisDocument 类中运行此示例。

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 安全性

请参见

参考

DocumentBase 类

Microsoft.Office.Tools.Word 命名空间