GroupContentControl 類別 (2007 系統)

更新: 2008 年 7 月

表示文件中使用者無法編輯或刪除的受保護區域。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v9.0 (在 Microsoft.Office.Tools.Word.v9.0.dll 中)

語法

<DefaultBindingPropertyAttribute("Text")> _
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public NotInheritable Class GroupContentControl _
    Inherits ContentControlBase _
    Implements ISupportInitializeControl, ISupportInitialize

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

備註

使用 GroupContentControl 定義文件中使用者無法編輯或刪除的受保護區域。GroupContentControl 可以包含任何文件項目,例如文字、資料表、圖形,甚至其他內容控制項。GroupContentControl 不會提供使用者看得到的 UI。如需使用 GroupContentControl 保護文件一部分的詳細資訊,請參閱內容控制項HOW TO:使用內容控制項保護文件的部分

內容控制項

GroupContentControl 是八種內容控制項型別的其中一個,可用來設計 Microsoft Office Word 中的文件和範本。內容控制項有一個使用者介面 (UI) 具有像表單一樣的受控制輸入。您可以使用內容控制項以避免使用者編輯文件或範本中被保護的區段,也可以將內容控制項繫結至資料來源。如需詳細資訊,請參閱內容控制項

範例

下列程式碼範例會在文件開頭加入新段落,並建立包含這個段落的新 GroupContentControl。GroupContentControl 可防止使用者編輯段落中的文字。

這是示範文件層級自訂的版本。若要使用這段程式碼,請將它貼到專案的 ThisDocument 類別中,並從 ThisDocument_Startup 方法呼叫 AddGroupControlAtSelection 方法。

Dim groupControl1 As Microsoft.Office.Tools.Word.GroupContentControl

Private Sub AddGroupControlAtSelection()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Text = "You cannot edit or change the formatting of text " & _
            "in this paragraph, because this paragraph is in a GroupContentControl."
    Me.Paragraphs(1).Range.Select()
    groupControl1 = Me.Controls.AddGroupContentControl("groupControl1")
End Sub
private Microsoft.Office.Tools.Word.GroupContentControl groupControl1;

private void AddGroupControlAtSelection()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Word.Range range1 = this.Paragraphs[1].Range;
    range1.Text = "You cannot edit or change the formatting of text " +
        "in this paragraph, because this paragraph is in a GroupContentControl.";
    range1.Select();

    groupControl1 = this.Controls.AddGroupContentControl("groupControl1");
}

這是示範應用程式層級增益集的版本。若要使用這段程式碼,請將它貼到專案的 ThisAddIn 類別中,並從 ThisAddIn_Startup 方法呼叫 AddGroupControlAtSelection 方法。

Dim groupControl1 As Microsoft.Office.Tools.Word.GroupContentControl

Private Sub AddGroupControlAtSelection()
    If Me.Application.ActiveDocument Is Nothing Then
        Return
    End If

    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
    vstoDoc.Paragraphs(1).Range.Text = "You cannot edit or change the formatting of text " & _
            "in this paragraph, because this paragraph is in a GroupContentControl."
    vstoDoc.Paragraphs(1).Range.Select()
    groupControl1 = vstoDoc.Controls.AddGroupContentControl("groupControl1")
End Sub
private Microsoft.Office.Tools.Word.GroupContentControl groupControl1;

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

    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    Word.Range range1 = vstoDoc.Paragraphs[1].Range;
    range1.Text = "You cannot edit or change the formatting of text " +
        "in this paragraph, because this paragraph is in a GroupContentControl.";
    range1.Select();

    groupControl1 = vstoDoc.Controls.AddGroupContentControl("groupControl1");
}

繼承階層架構

System.Object
  Microsoft.VisualStudio.Tools.Office.RemoteComponent
    Microsoft.VisualStudio.Tools.Office.RemoteBindableComponent
      Microsoft.Office.Tools.Word.ContentControlBase
        Microsoft.Office.Tools.Word.GroupContentControl

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

請參閱

參考

GroupContentControl 成員

Microsoft.Office.Tools.Word 命名空間

其他資源

內容控制項

HOW TO:將內容控制項加入至 Word 文件

HOW TO:使用內容控制項保護文件的部分

逐步解說:使用內容控制項建立範本

變更記錄

日期

記錄

原因

2008 年 7 月

加入應用程式層級增益集的程式碼範例版本。

SP1 功能變更。