PlainTextContentControl 介面

代表文件中的文字區塊。

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

語法

'宣告
<GuidAttribute("a8c46931-fa10-4760-8b46-0f2d881e269f")> _
Public Interface PlainTextContentControl _
    Inherits ContentControlBase, IBindableComponent, IComponent, IDisposable,  _
    ISupportInitialize
[GuidAttribute("a8c46931-fa10-4760-8b46-0f2d881e269f")]
public interface PlainTextContentControl : ContentControlBase, 
    IBindableComponent, IComponent, IDisposable, ISupportInitialize

PlainTextContentControl 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 Application 取得 Microsoft.Office.Interop.Word.Application,代表 Microsoft Office Word 目前的執行個體。
公用屬性 BindingContext 取得或設定 IBindableComponent 的 Currency 管理員集合。 (繼承自 IBindableComponent)。
公用屬性 Container 基礎架構。 (繼承自 ContentControlBase)。
公用屬性 ContainerComponent 基礎架構。 (繼承自 ContentControlBase)。
公用屬性 Creator 取得 32 位元整數,表示在其中建立 PlainTextContentControl 的應用程式。
公用屬性 DataBindings 取得這個 IBindableComponent 的資料繫結物件集合。 (繼承自 IBindableComponent)。
公用屬性 DefaultDataSourceUpdateMode 取得或設定 ContentControlBase 的預設 DataSourceUpdateMode。 (繼承自 ContentControlBase)。
公用屬性 DefaultTextStyle 取得要用來格式化 PlainTextContentControl 中之文字的字元樣式名稱。
公用屬性 ID 取得識別內容控制項的唯一號碼。 (繼承自 ContentControlBase)。
公用屬性 InnerObject 取得 Microsoft.Office.Tools.Word.ContentControlBase 的基礎 Microsoft.Office.Interop.Word.ContentControl 物件。 (繼承自 ContentControlBase)。
公用屬性 LockContentControl 取得或設定值,這個值指定是否可以從文件中刪除 PlainTextContentControl。
公用屬性 LockContents 取得或設定值,這個值指定是否可以編輯 PlainTextContentControl 的內容。
公用屬性 MultiLine 取得或設定值,這個值指定 PlainTextContentControl 是否可以包含分行符號。
公用屬性 Parent 取得 PlainTextContentControl 的父代 (Parent)。
公用屬性 ParentContentControl 取得以巢狀方式置於另一個內容控制項中之 PlainTextContentControl 的父內容控制項。
公用屬性 PlaceholderText 取得或設定 PlainTextContentControl 中顯示的文字,直到該文字被使用者動作或其他作業變更為止。
公用屬性 Range 取得表示 PlainTextContentControl 內容的 Range
公用屬性 ShowingPlaceholderText 取得值,這個值指定 PlainTextContentControl 目前是否顯示預留位置文字。
公用屬性 Site 取得或設定與 IComponent 相關聯的 ISite。 (繼承自 IComponent)。
公用屬性 Tag 取得或設定要與 PlainTextContentControl 產生關聯的字串。
公用屬性 Temporary 取得或設定值,這個值指定編輯 PlainTextContentControl 控制項時,是否會從文件中自動刪除此控制項。
公用屬性 Text 取得或設定 PlainTextContentControl 中的文字。
公用屬性 Title 取得或設定 PlainTextContentControl 的標題。
公用屬性 XMLMapping 取得 XMLMapping,表示 PlainTextContentControl 和自訂 XML 組件的項目之間的繫結。

回頁首

方法

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

回頁首

事件

  名稱 說明
公用事件 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)。

回頁首

備註

PlainTextContentControl 只能包含文字。 您可以將 PlainTextContentControl 中的文字格式化,但該控制項中的所有文字都會自動使用相同的格式。 例如,如果您將 PlainTextContentControl 之句子裡某個字設定為斜體,則該控制項內的所有文字都是斜體。

若要存取 PlainTextContentControl 中的文字,請使用 Text 屬性。 根據預設,PlainTextContentControl 無法包含分行符號。 若要變更這個行為,請使用 MultiLine 屬性。

若要建立一個可包含文字及許多其他內容類型的文件區,包括資料表、圖片或其他內容控制項,請使用 RichTextContentControl

注意事項注意事項

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

內容控制項

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

使用方式

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

範例

下列程式碼範例會將新的 PlainTextContentControl 加入至文件的開頭。

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

Dim plainTextControl1 As Microsoft.Office.Tools.Word.PlainTextContentControl

Private Sub AddPlainTextControlAtSelection()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Select()
    plainTextControl1 = Me.Controls.AddPlainTextContentControl("plainTextControl1")
    plainTextControl1.PlaceholderText = "Enter your first name"
End Sub
private Microsoft.Office.Tools.Word.PlainTextContentControl textControl1;

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

    textControl1 = this.Controls.AddPlainTextContentControl("textControl1");
    textControl1.PlaceholderText = "Enter your first name";
}

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

Dim plainTextControl1 As Microsoft.Office.Tools.Word.PlainTextContentControl

Private Sub AddPlainTextControlAtSelection()
    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.Select()
    plainTextControl1 = vstoDoc.Controls.AddPlainTextContentControl("plainTextControl1")
    plainTextControl1.PlaceholderText = "Enter your first name"
End Sub
private Microsoft.Office.Tools.Word.PlainTextContentControl textControl1;

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

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

    textControl1 = vstoDoc.Controls.AddPlainTextContentControl("textControl1");
    textControl1.PlaceholderText = "Enter your first name";
}

請參閱

參考

Microsoft.Office.Tools.Word 命名空間

其他資源

內容控制項

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

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

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

逐步解說:將內容控制項繫結至自訂 XML 組件