次の方法で共有


ControlCollection.AddPlainTextContentControl メソッド (Range, String) (2007 System)

更新 : 2008 年 7 月

新しい PlainTextContentControl を指定された範囲で文書に追加します。

名前空間 :  Microsoft.Office.Tools.Word
アセンブリ :  Microsoft.Office.Tools.Word.v9.0 (Microsoft.Office.Tools.Word.v9.0.dll 内)

構文

'宣言
Public Function AddPlainTextContentControl ( _
    range As Range, _
    name As String _
) As PlainTextContentControl
'使用
Dim instance As ControlCollection
Dim range As Range
Dim name As String
Dim returnValue As PlainTextContentControl

returnValue = instance.AddPlainTextContentControl(range, _
    name)
public PlainTextContentControl AddPlainTextContentControl(
    Range range,
    string name
)

パラメータ

戻り値

型 : Microsoft.Office.Tools.Word.PlainTextContentControl

文書に追加された PlainTextContentControl

例外

例外 条件
ArgumentNullException

name が nullnull 参照 (Visual Basic では Nothing) であるか、または長さが 0 である場合。

ControlNameAlreadyExistsException

同じ名前のコントロールが既に ControlCollection に存在する場合。

解説

このメソッドを使用して、実行時における文書の指定された範囲で新しい PlainTextContentControl を追加します。詳細については、「実行時の Office ドキュメントへのコントロールの追加」を参照してください。

次のコード例は、文書の先頭に新しい PlainTextContentControl を追加します。

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

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

このバージョンは、アプリケーション レベルのアドインに使用されます。このコードを使用するには、プロジェクトの ThisAddIn クラスにコードを貼り付け、ThisAddIn_Startup メソッドから AddTextControlAtRange メソッドを呼び出します。

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 = Me.Application.ActiveDocument.GetVstoObject()
    vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
    plainTextControl2 = vstoDoc.Controls.AddPlainTextContentControl( _
        vstoDoc.Paragraphs(1).Range, "plainTextControl2")
    plainTextControl2.PlaceholderText = "Enter your first name"
End Sub
private Microsoft.Office.Tools.Word.PlainTextContentControl textControl2;

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

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

    textControl2 = vstoDoc.Controls.AddPlainTextContentControl(
        vstoDoc.Paragraphs[1].Range,
        "textControl2");
    textControl2.PlaceholderText = "Enter your first name";
}

アクセス許可

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

ControlCollection クラス

ControlCollection メンバ

AddPlainTextContentControl オーバーロード

Microsoft.Office.Tools.Word 名前空間

その他の技術情報

実行時の Office ドキュメントへのコントロールの追加

ホスト コントロールのヘルパー メソッド

方法 : Word 文書にコンテンツ コントロールを追加する

履歴の変更

日付

履歴

理由

2008 年 7 月

アプリケーション レベルのアドインのコード例のバージョンを追加

SP1 機能変更