مشاركة عبر


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

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

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

بناء الجملة

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

المعلمات

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

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

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

استثناءات

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

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

-أو-

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

ControlNameAlreadyExistsException

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

ArgumentException

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

ملاحظات

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

أمثلة

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

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

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

Private Sub CreateBuildingBlockGalleryControlsFromNativeControls()
    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.wdContentControlBuildingBlockGallery Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl = _
                Me.Controls.AddBuildingBlockGalleryContentControl(nativeControl, _
                "VSTOBuildingBlockGalleryContentControl" + count.ToString())
            buildingBlockControls.Add(tempControl)
        End If
    Next nativeControl
End Sub
private System.Collections.Generic.List
   <Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl> buildingBlockControls;

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

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

    foreach (Word.ContentControl nativeControl in this.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlBuildingBlockGallery)
        {
            count++;
            Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl tempControl =
                this.Controls.AddBuildingBlockGalleryContentControl(nativeControl,
                "VSTOBuildingBlockContentControl" + count.ToString());
            buildingBlockControls.Add(tempControl);
        }
    }
}

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

Private buildingBlockControls As New System.Collections.Generic.List _
        (Of BuildingBlockGalleryContentControl)

Private Sub CreateBuildingBlockGalleryControlsFromNativeControls()
    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.wdContentControlBuildingBlockGallery Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl = _
                vstoDoc.Controls.AddBuildingBlockGalleryContentControl(nativeControl, _
                "VSTOBuildingBlockGalleryContentControl" + count.ToString())
            buildingBlockControls.Add(tempControl)
        End If
    Next nativeControl
End Sub
private System.Collections.Generic.List
   <Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl> buildingBlockControls;

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

    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    if (vstoDoc.ContentControls.Count <= 0)
    {
        System.Windows.Forms.MessageBox.Show("No content controls found in document.");                    
        return;
    }

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

    foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlBuildingBlockGallery)
        {
            count++;
            Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl tempControl =
                vstoDoc.Controls.AddBuildingBlockGalleryContentControl(nativeControl,
                "VSTOBuildingBlockContentControl" + count.ToString());
            buildingBlockControls.Add(tempControl);
        }
    }
}

يلي تعليمات برمجية المثال، يتم إنشاء جديد BuildingBlockGalleryContentControlلكل معرض كتل الإنشاء الأصلي مستخدم بإضافتها إلى المستند.

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

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

    If NewContentControl.Type = Word.WdContentControlType.wdContentControlBuildingBlockGallery Then
        Me.Controls.AddBuildingBlockGalleryContentControl(NewContentControl, _
            "BuildingBlockControl" + NewContentControl.ID)
    End If
End Sub
void ThisDocument_BuildingBlockContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlBuildingBlockGallery)
    {
        this.Controls.AddBuildingBlockGalleryContentControl(NewContentControl,
            "BuildingBlockControl" + NewContentControl.ID);
    }
}

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

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

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

أمن NET Framework.

راجع أيضًَا

المرجع

ControlCollection واجهة

ControlCollection الأعضاء

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

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

موارد أخرى

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

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

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