GroupContentControl 介面

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

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

語法

'宣告
<GuidAttribute("1fc77d35-6978-4dbc-a615-9ed8a8f728f5")> _
Public Interface GroupContentControl _
    Inherits ContentControlBase, IBindableComponent, IComponent, IDisposable,  _
    ISupportInitialize
[GuidAttribute("1fc77d35-6978-4dbc-a615-9ed8a8f728f5")]
public interface GroupContentControl : ContentControlBase, 
    IBindableComponent, IComponent, IDisposable, ISupportInitialize

GroupContentControl 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 Application 取得 Microsoft.Office.Interop.Word.Application,代表 Microsoft Office Word 目前的執行個體。
公用屬性 BindingContext 取得或設定貨幣經理要使用的集合IBindableComponent。 (繼承自 IBindableComponent)。
公用屬性 Container 基礎架構。 (繼承自 ContentControlBase)。
公用屬性 ContainerComponent 基礎架構。 (繼承自 ContentControlBase)。
公用屬性 Creator 取得 32 位元整數,表示在其中建立 GroupContentControl 的應用程式。
公用屬性 DataBindings 取得資料繫結物件的集合,此IBindableComponent。 (繼承自 IBindableComponent)。
公用屬性 DefaultDataSourceUpdateMode 取得或設定 ContentControlBase 的預設 DataSourceUpdateMode。 (繼承自 ContentControlBase)。
公用屬性 ID 取得識別內容控制項的唯一號碼。 (繼承自 ContentControlBase)。
公用屬性 InnerObject 取得 Microsoft.Office.Tools.Word.ContentControlBase 的基礎 Microsoft.Office.Interop.Word.ContentControl 物件。 (繼承自 ContentControlBase)。
公用屬性 LockContentControl 取得或設定值,這個值指定是否可以從文件中刪除 GroupContentControl。
公用屬性 Parent 取得 GroupContentControl 的父代 (Parent)。
公用屬性 ParentContentControl 取得以巢狀方式置於另一個內容控制項中之 GroupContentControl 的父內容控制項。
公用屬性 Range 取得 Range,表示 GroupContentControl 的內容。
公用屬性 Site 取得或設定與 IComponent 相關聯的 ISite。 (繼承自 IComponent)。
公用屬性 Tag 取得或設定要與 GroupContentControl 產生關聯的字串。
公用屬性 Text 取得 GroupContentControl 中的文字。
公用屬性 Title 取得或設定 GroupContentControl 的標題。

回頁首

方法

  名稱 說明
公用方法 BeginInit 表示物件正在啟動初始設定。 (繼承自 ISupportInitialize)。
公用方法 Copy 將 GroupContentControl 從文件複製到 [剪貼簿]。
公用方法 Cut 從文件移除 GroupContentControl 並將它加入至 [剪貼簿]。
公用方法 Delete 從文件中刪除動態建立的內容控制項,並從文件中的 ControlCollection 移除這個內容控制項。 (繼承自 ContentControlBase)。
公用方法 Dispose 執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。 (繼承自 IDisposable)。
公用方法 EndInit 表示物件已完成初始設定。 (繼承自 ISupportInitialize)。

回頁首

事件

  名稱 說明
公用事件 Added 在內容控制項加入至文件之後發生。 (繼承自 ContentControlBase)。
公用事件 BindingContextChanged ContentControlBaseBindingContext 屬性值變更時發生。 (繼承自 ContentControlBase)。
公用事件 ContentUpdating 如果內容控制項已繫結至自訂 XML 組件,只在 Microsoft Office Word 更新內容控制項中的文字之前發生。 (繼承自 ContentControlBase)。
公用事件 Deleting 只在內容控制項從文件中刪除之前發生。 (繼承自 ContentControlBase)。
公用事件 Disposed 表示處理元件的 Disposed 事件的方法。 (繼承自 IComponent)。
公用事件 Entering 當使用者在內容控制項中按一下或以程式設計方式將游標移至內容控制項時發生。 (繼承自 ContentControlBase)。
公用事件 Exiting 當使用者在內容控制項外部按一下或以程式設計方式將游標移至內容控制項外部時發生。 (繼承自 ContentControlBase)。
公用事件 StoreUpdating 只在 Microsoft Office Word 更新已繫結至內容控制項之自訂 XML 組件中的資料之前發生 (也就是,在內容控制項中的文字變更之後)。 (繼承自 ContentControlBase)。
公用事件 Validated 在成功驗證內容控制項時發生。 (繼承自 ContentControlBase)。
公用事件 Validating 驗證內容控制項的內容時發生。 (繼承自 ContentControlBase)。

回頁首

備註

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

注意事項注意事項

這個介面是由 Visual Studio Tools for Office Runtime 實作,並不能實作於您的程式碼中。如需詳細資訊,請參閱 Visual Studio Tools for Office Runtime 概觀

內容控制項

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

使用方式

本文件說明此類型用於以 .NET Framework 4 和 .NET Framework 4.5 為目標之 Office 專案的版本。在以 .NET Framework 3.5 為目標的專案中,此類型可能會有不同的成員,而為此類型提供的程式碼範例可能無法運作。如需此類型在以 .NET Framework 3.5 為目標之專案中的相關文件,請參閱下列 Visual Studio 2008 文件中的參考章節:https://go.microsoft.com/fwlink/?LinkId=160658

範例

下列程式碼範例會在文件開頭加入新段落,並建立包含這個段落的新 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 = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    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 = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    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");
}

請參閱

參考

Microsoft.Office.Tools.Word 命名空間

其他資源

內容控制項

如何:將內容控制項加入至 Word 文件

如何:使用內容控制項保護文件的部分

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