مشاركة عبر


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

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

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

بناء الجملة

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

المعلمات

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

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

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

استثناءات

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

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

-أو-

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

ControlNameAlreadyExistsException

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

ArgumentException

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

ملاحظات

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

أمثلة

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

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

Private comboBoxControls As New System.Collections.Generic.List _
        (Of Microsoft.Office.Tools.Word.ComboBoxContentControl)

Private Sub CreateComboBoxControlsFromNativeControls()
    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.wdContentControlComboBox Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.ComboBoxContentControl = _
                Me.Controls.AddComboBoxContentControl(nativeControl, _
                "VSTOComboBoxContentControl" + count.ToString())
            comboBoxControls.Add(tempControl)
        End If
    Next nativeControl
End Sub
private System.Collections.Generic.List
    <Microsoft.Office.Tools.Word.ComboBoxContentControl> comboBoxControls;

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

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

    foreach (Word.ContentControl nativeControl in this.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlComboBox)
        {
            count++;
            Microsoft.Office.Tools.Word.ComboBoxContentControl tempControl =
                this.Controls.AddComboBoxContentControl(nativeControl,
                "VSTOComboBoxContentControl" + count.ToString());
            comboBoxControls.Add(tempControl);
        }
    }
}

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

Private comboBoxControls As New System.Collections.Generic.List _
        (Of Microsoft.Office.Tools.Word.ComboBoxContentControl)

Private Sub CreateComboBoxControlsFromNativeControls()
    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.wdContentControlComboBox Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.ComboBoxContentControl = _
                vstoDoc.Controls.AddComboBoxContentControl(nativeControl, _
                "VSTOComboBoxContentControl" + count.ToString())
            comboBoxControls.Add(tempControl)
        End If
    Next nativeControl
End Sub
private System.Collections.Generic.List
    <Microsoft.Office.Tools.Word.ComboBoxContentControl> comboBoxControls;

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

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

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

    foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlComboBox)
        {
            count++;
            Microsoft.Office.Tools.Word.ComboBoxContentControl tempControl =
                vstoDoc.Controls.AddComboBoxContentControl(nativeControl,
                "VSTOComboBoxContentControl" + count.ToString());
            comboBoxControls.Add(tempControl);
        }
    }
}

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

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

Private Sub ThisDocument_ComboBoxContentControlAfterAdd(ByVal NewContentControl As Word.ContentControl, _
    ByVal InUndoRedo As Boolean) Handles Me.ContentControlAfterAdd

    If NewContentControl.Type = Word.WdContentControlType.wdContentControlComboBox Then
        Me.Controls.AddComboBoxContentControl(NewContentControl, _
            "ComboBoxControl" + NewContentControl.ID)
    End If
End Sub
void ThisDocument_ComboBoxContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlComboBox)
    {
        this.Controls.AddComboBoxContentControl(NewContentControl,
            "ComboBoxControl" + NewContentControl.ID);
    }
}

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

Private Sub ActiveDocument_ComboBoxContentControlAfterAdd( _
    ByVal NewContentControl As Word.ContentControl, _
    ByVal InUndoRedo As Boolean)

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    If NewContentControl.Type = Word.WdContentControlType. _
        wdContentControlComboBox Then
        vstoDoc.Controls.AddComboBoxContentControl(NewContentControl, _
            "ComboBoxControl" + NewContentControl.ID)
    End If
End Sub
void ActiveDocument_ComboBoxContentControlAfterAdd(
    Word.ContentControl NewContentControl, bool InUndoRedo)
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlComboBox)
    {
        vstoDoc.Controls.AddComboBoxContentControl(NewContentControl,
            "ComboBoxControl" + NewContentControl.ID);
    }
}

أمن NET Framework.

راجع أيضًَا

المرجع

ControlCollection واجهة

ControlCollection الأعضاء

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

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

موارد أخرى

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

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

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