Share via


ControlCollection.AddPlainTextContentControl メソッド

定義

オーバーロード

AddPlainTextContentControl(String)

ドキュメントの現在の選択範囲に新しい PlainTextContentControl を追加します。

AddPlainTextContentControl(ContentControl, String)

ドキュメント内のネイティブなコンテンツ コントロールに基づいた新しい PlainTextContentControl を追加します。

AddPlainTextContentControl(Range, String)

ドキュメント内の指定した範囲に新しい PlainTextContentControl を追加します。

AddPlainTextContentControl(String)

ドキュメントの現在の選択範囲に新しい PlainTextContentControl を追加します。

public:
 Microsoft::Office::Tools::Word::PlainTextContentControl ^ AddPlainTextContentControl(System::String ^ name);
public Microsoft.Office.Tools.Word.PlainTextContentControl AddPlainTextContentControl (string name);
abstract member AddPlainTextContentControl : string -> Microsoft.Office.Tools.Word.PlainTextContentControl
Public Function AddPlainTextContentControl (name As String) As PlainTextContentControl

パラメーター

name
String

新しいコントロールの名前。

戻り値

ドキュメントに追加された PlainTextContentControl

例外

name は、null であるか、または長さがゼロです。

ControlCollection に既に同じ名前のコントロールがあります。

次のコード例では、ドキュメントの先頭に新しい PlainTextContentControl を追加します。

このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの ThisDocument クラスに貼り付け、 メソッドから メソッドをAddTextControlAtSelectionThisDocument_Startup呼び出します。

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";
}
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

このバージョンは、.NET Framework 4 または .NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、プロジェクトの ThisAddIn クラスに貼り付け、 メソッドから メソッドをAddTextControlAtSelectionThisAddIn_Startup呼び出します。

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";
}
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

注釈

実行時に文書内の現在の選択範囲に新しい PlainTextContentControl を追加するには、このメソッドを使用します。 詳細については、「 Adding Controls to Office Documents at Run Time」を参照してください。

適用対象

AddPlainTextContentControl(ContentControl, String)

ドキュメント内のネイティブなコンテンツ コントロールに基づいた新しい PlainTextContentControl を追加します。

public:
 Microsoft::Office::Tools::Word::PlainTextContentControl ^ AddPlainTextContentControl(Microsoft::Office::Interop::Word::ContentControl ^ contentControl, System::String ^ name);
public Microsoft.Office.Tools.Word.PlainTextContentControl AddPlainTextContentControl (Microsoft.Office.Interop.Word.ContentControl contentControl, string name);
abstract member AddPlainTextContentControl : Microsoft.Office.Interop.Word.ContentControl * string -> Microsoft.Office.Tools.Word.PlainTextContentControl
Public Function AddPlainTextContentControl (contentControl As ContentControl, name As String) As PlainTextContentControl

パラメーター

contentControl
ContentControl

新しいコントロールのベースとなる ContentControl

name
String

新しいコントロールの名前。

戻り値

ドキュメントに追加された PlainTextContentControl

例外

contentControlnull.-or- name または の null 長さが 0 です。

ControlCollection に既に同じ名前のコントロールがあります。

contentControlは文書パーツ ギャラリーではありません (つまり、 TypecontentControl プロパティに Microsoft.Office.Interop.Word の値がありません。WdContentControlType.wdContentControlText)。

次のコード例では、ドキュメント内のすべてのネイティブ プレーン テキスト コントロールに対して新しい PlainTextContentControl を作成します。

このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの ThisDocument クラスに貼り付け、 メソッドから メソッドをCreateTextControlsFromNativeControlsThisDocument_Startup呼び出します。

private System.Collections.Generic.List<Microsoft.Office.Tools.Word.PlainTextContentControl> plainTextControls;

private void CreateTextControlsFromNativeControls()
{
    if (this.ContentControls.Count <= 0)
        return;

    plainTextControls = new System.Collections.Generic.List
        <Microsoft.Office.Tools.Word.PlainTextContentControl>();
    int count = 0;

    foreach (Word.ContentControl nativeControl in this.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlText)
        {
            count++;
            Microsoft.Office.Tools.Word.PlainTextContentControl tempControl =
                this.Controls.AddPlainTextContentControl(nativeControl,
                "VSTOPlainTextContentControl" + count.ToString());
            plainTextControls.Add(tempControl);
        }
    }
}
Private plainTextControls As New System.Collections.Generic.List _
    (Of Microsoft.Office.Tools.Word.PlainTextContentControl)

Private Sub CreatePlainTextControlsFromNativeControls()
    If Me.ContentControls.Count <= 0 Then
        Return
    End If

    Dim count As Integer = 0
    For Each nativeControl As Word.ContentControl In Me.ContentControls
        If nativeControl.Type = Word.WdContentControlType.wdContentControlText Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.PlainTextContentControl = _
                Me.Controls.AddPlainTextContentControl(nativeControl, _
                "VSTOPlainTextContentControl" + count.ToString())
            plainTextControls.Add(tempControl)
        End If
    Next nativeControl
End Sub

このバージョンは、.NET Framework 4 または .NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、プロジェクトの ThisAddIn クラスに貼り付け、 メソッドから メソッドをCreateTextControlsFromNativeControlsThisAddIn_Startup呼び出します。

private System.Collections.Generic.List<Microsoft.Office.Tools.Word.PlainTextContentControl> plainTextControls;

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

    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    if (vstoDoc.ContentControls.Count <= 0)
        return;

    plainTextControls = new System.Collections.Generic.List
        <Microsoft.Office.Tools.Word.PlainTextContentControl>();
    int count = 0;

    foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlText)
        {
            count++;
            Microsoft.Office.Tools.Word.PlainTextContentControl tempControl =
                vstoDoc.Controls.AddPlainTextContentControl(nativeControl,
                "VSTOPlainTextContentControl" + count.ToString());
            plainTextControls.Add(tempControl);
        }
    }
}
Private plainTextControls As New System.Collections.Generic.List _
    (Of Microsoft.Office.Tools.Word.PlainTextContentControl)

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

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    If vstoDoc.ContentControls.Count <= 0 Then
        Return
    End If

    Dim count As Integer = 0
    For Each nativeControl As Word.ContentControl In vstoDoc.ContentControls
        If nativeControl.Type = Word.WdContentControlType.wdContentControlText Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.PlainTextContentControl = _
                vstoDoc.Controls.AddPlainTextContentControl(nativeControl, _
                "VSTOPlainTextContentControl" + count.ToString())
            plainTextControls.Add(tempControl)
        End If
    Next nativeControl
End Sub

次のコード例では、ユーザーがドキュメントに追加するすべてのネイティブ プレーン テキスト コントロールに対して新しい PlainTextContentControl を作成します。

このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの クラスに ThisDocument 貼り付けます。 C# の場合は、イベント ハンドラーを ThisDocument_PlainTextContentControlAfterAdd クラスの ThisDocument イベントにContentControlAfterAddアタッチする必要もあります。

void ThisDocument_PlainTextContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlText)
    {
        this.Controls.AddPlainTextContentControl(NewContentControl,
            "PlainTextControl" + NewContentControl.ID);
    }
}
Private Sub ThisDocument_PlainTextContentControlAfterAdd(ByVal NewContentControl As Word.ContentControl, _
    ByVal InUndoRedo As Boolean) Handles Me.ContentControlAfterAdd

    If NewContentControl.Type = Word.WdContentControlType.wdContentControlText Then
        Me.Controls.AddPlainTextContentControl(NewContentControl, _
            "PlainTextControl" + NewContentControl.ID)
    End If
End Sub

このバージョンは、.NET Framework 4 または .NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、プロジェクトの クラスに ThisAddIn 貼り付けます。 また、作業中の文書の ActiveDocument_PlainTextContentControlAfterAdd イベントにイベント ハンドラーを ContentControlAfterAdd アタッチする必要があります。

void ActiveDocument_PlainTextContentControlAfterAdd(
    Word.ContentControl NewContentControl, bool InUndoRedo)
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlText)
    {
        vstoDoc.Controls.AddPlainTextContentControl(NewContentControl,
            "PlainTextControl" + NewContentControl.ID);
    }
}
Private Sub ActiveDocument_PlainTextContentControlAfterAdd( _
    ByVal NewContentControl As Word.ContentControl, _
    ByVal InUndoRedo As Boolean)

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    If NewContentControl.Type = Word.WdContentControlType. _
        wdContentControlText Then
        vstoDoc.Controls.AddPlainTextContentControl(NewContentControl, _
            "PlainTextControl" + NewContentControl.ID)
    End If
End Sub

注釈

実行時にドキュメント内のネイティブ コンテンツ コントロールに基づく新しい PlainTextContentControl を追加するには、このメソッドを使用します。 これは、実行時に を PlainTextContentControl 作成し、次にドキュメントを開いたときに同じコントロールを再作成する場合に便利です。 詳細については、「 Adding Controls to Office Documents at Run Time」を参照してください。

適用対象

AddPlainTextContentControl(Range, String)

ドキュメント内の指定した範囲に新しい PlainTextContentControl を追加します。

public:
 Microsoft::Office::Tools::Word::PlainTextContentControl ^ AddPlainTextContentControl(Microsoft::Office::Interop::Word::Range ^ range, System::String ^ name);
public Microsoft.Office.Tools.Word.PlainTextContentControl AddPlainTextContentControl (Microsoft.Office.Interop.Word.Range range, string name);
abstract member AddPlainTextContentControl : Microsoft.Office.Interop.Word.Range * string -> Microsoft.Office.Tools.Word.PlainTextContentControl
Public Function AddPlainTextContentControl (range As Range, name As String) As PlainTextContentControl

パラメーター

range
Range

新しいコントロールの境界を指定する Range

name
String

新しいコントロールの名前。

戻り値

ドキュメントに追加された PlainTextContentControl

例外

name は、null であるか、または長さがゼロです。

ControlCollection に既に同じ名前のコントロールがあります。

次のコード例では、ドキュメントの先頭に新しい PlainTextContentControl を追加します。

このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの ThisDocument クラスに貼り付け、 メソッドから メソッドをAddTextControlAtRangeThisDocument_Startup呼び出します。

private Microsoft.Office.Tools.Word.PlainTextContentControl textControl2;

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

    textControl2 = this.Controls.AddPlainTextContentControl(this.Paragraphs[1].Range,
        "textControl2");
    textControl2.PlaceholderText = "Enter your first name";
}
Dim plainTextControl2 As Microsoft.Office.Tools.Word.PlainTextContentControl

Private Sub AddPlainTextControlAtRange()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    plainTextControl2 = Me.Controls.AddPlainTextContentControl(Me.Paragraphs(1).Range, "plainTextControl2")
    plainTextControl2.PlaceholderText = "Enter your first name"
End Sub

このバージョンは、.NET Framework 4 または .NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、プロジェクトの ThisAddIn クラスに貼り付け、 メソッドから メソッドをAddTextControlAtRangeThisAddIn_Startup呼び出します。

private Microsoft.Office.Tools.Word.PlainTextContentControl textControl2;

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

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

    textControl2 = vstoDoc.Controls.AddPlainTextContentControl(
        vstoDoc.Paragraphs[1].Range,
        "textControl2");
    textControl2.PlaceholderText = "Enter your first name";
}
Dim plainTextControl2 As Microsoft.Office.Tools.Word.PlainTextContentControl

Private Sub AddPlainTextControlAtRange()
    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()
    plainTextControl2 = vstoDoc.Controls.AddPlainTextContentControl( _
        vstoDoc.Paragraphs(1).Range, "plainTextControl2")
    plainTextControl2.PlaceholderText = "Enter your first name"
End Sub

注釈

実行時にドキュメント内の指定した範囲に新しい PlainTextContentControl を追加するには、このメソッドを使用します。 詳細については、「 Adding Controls to Office Documents at Run Time」を参照してください。

適用対象