مشاركة عبر


ControlCollection.AddPlainTextContentControl أسلوب (ContentControl, String)

قم بإضافة جديد PlainTextContentControlالتي هو استناداً إلى عنصر تحكم محتوى أصلي في مستند.

مساحة الاسم:  Microsoft.Office.Tools.Word
التجميع:  Microsoft.Office.Tools.Word (في Microsoft.Office.Tools.Word.dll)

بناء الجملة

'إقرار
Function AddPlainTextContentControl ( _
    contentControl As ContentControl, _
    name As String _
) As PlainTextContentControl
PlainTextContentControl AddPlainTextContentControl(
    ContentControl contentControl,
    string name
)

المعلمات

  • name
    النوع: System.String
    اسم جديد عنصر تحكم.

القيمة المُرجعة

النوع: Microsoft.Office.Tools.Word.PlainTextContentControl
PlainTextContentControlالتي تمت إضافتها إلى مستند.

استثناءات

استثناء: شرط
ArgumentNullException

contentControl هو nullمرجع خالٍ (لا شيء في Visual Basic).

-أو-

nameهوnullمرجع خالٍ (لا شيء في Visual Basic)أو صفرية الطول.

ControlNameAlreadyExistsException

عنصر تحكم بنفس الاسم هو موجود بالفعل في ControlCollection.

ArgumentException

contentControlلا إنشاء? المعرض كتلة (هو Typeخاصية contentControlلا يحتوي القيمة Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlText).

ملاحظات

استخدام ترتيب هو طريقة لإضافة جديد PlainTextContentControlالتي هو استناداً إلى عنصر تحكم محتوى أصلي في مستند في وقت التشغيل. Th هو هو مفيداً عندما تقوم بإنشاء PlainTextContentControlفي وقت التشغيل، وكنت ترغب في إعادة إنشاء عنصر التحكم نفسه المرة القادمة مستند هو فتح. لمزيد من المعلومات، راجع إضافة عناصر إلى مستندات Office في وقت التشغيل.

أمثلة

إنشاء مثال التعليمة البرمجية التالية جديدة PlainTextContentControlلكل نص عادي أصلي التحكم التي هو في التطبيق.

Th هو الإصدار هو لتخصيص المستوى مستند. إلى استخدام هذا الرمز، قم بلصقه في إلى ThisDocumentالفئة في مشروع، واستدعاء CreateTextControlsFromNativeControlsأسلوب من ThisDocument_Startupالأسلوب.

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

Th هو الإصدار هو لالمستوى تطبيق الوظيفة الإضافية التي تستهدف .NET Framework 4. إلى استخدام هذا الرمز، قم بلصقه في إلى ThisAddInالفئة في مشروع، واستدعاء CreateTextControlsFromNativeControlsأسلوب من ThisAddIn_Startupالأسلوب.

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

يلي تعليمات برمجية المثال، يتم إنشاء جديد PlainTextContentControlلكل عنصر تحكم نص عادي أصلي يضيف مستخدم للتطبيق.

Th هو الإصدار هو لتخصيص المستوى مستند. لاستخدام هذا تعليمات برمجية، لصقه في ThisDocumentالفئة في مشروع الخاص بك. C#، يجب يرفق ThisDocument_PlainTextContentControlAfterAddمعالج الأحداث إلى ContentControlAfterAddحدث الخاص ThisDocumentفئة.

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
void ThisDocument_PlainTextContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlText)
    {
        this.Controls.AddPlainTextContentControl(NewContentControl,
            "PlainTextControl" + NewContentControl.ID);
    }
}

Th هو الإصدار هو لالمستوى تطبيق الوظيفة الإضافية التي تستهدف .NET Framework 4. لاستخدام هذا تعليمات برمجية، لصقه في ThisAddInالفئة في مشروع الخاص بك. أيضا، يجب يرفق ActiveDocument_PlainTextContentControlAfterAddمعالج الأحداث إلى ContentControlAfterAddالأحداث من التطبيق النشط.

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

أمن NET Framework.

راجع أيضًَا

المرجع

ControlCollection واجهة

ControlCollection الأعضاء

AddPlainTextContentControl التحميل الزائد

Microsoft.Office.Tools.Word مساحة الاسم

موارد أخرى

إضافة عناصر إلى مستندات Office في وقت التشغيل

طرق المساعد عناصر تحكم المضيف

كيفية: إضافة عناصر تحكم المحتوى إلى مستندات Word