Aracılığıyla paylaş


ControlCollection.AddBuildingBlockGalleryContentControl Yöntem (ContentControl, String)

Yeni bir ekler BuildingBlockGalleryContentControl koleksiyonuna.Yeni denetim zaten belgede olan yerel içerik denetimi dayanır.

Ad alanı:  Microsoft.Office.Tools.Word
Derleme:  Microsoft.Office.Tools.Word (Microsoft.Office.Tools.Word.dll içinde)

Sözdizimi

'Bildirim
Function AddBuildingBlockGalleryContentControl ( _
    contentControl As ContentControl, _
    name As String _
) As BuildingBlockGalleryContentControl
BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl(
    ContentControl contentControl,
    string name
)

Parametreler

Dönüş Değeri

Tür: Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
BuildingBlockGalleryContentControl Belgeye eklenmiştir.

Özel Durumlar

Exception Koşul
ArgumentNullException

contentControlis nullnull başvuru (Visual Basic'te Nothing).

-veya-

nameise nullnull başvuru (Visual Basic'te Nothing) veya sıfır uzunlukta.

ControlNameAlreadyExistsException

Aynı ada sahip bir denetim içinde ControlCollection.

ArgumentException

contentControlyapıtaşı Galerisi değil (yani, Type özelliği contentControl değeri yok Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlBuildingBlockGallery).

Notlar

Yeni eklemek için bu yöntemi kullanın BuildingBlockGalleryContentControl belgeyi özgün içerik denetimi dayanır.Oluşturduğunuzda, bu yararlı bir BuildingBlockGalleryContentControl çalışma zamanında ve belge açıldığında bir sonraki açışınızda aynı denetimi yeniden istiyor.Daha fazla bilgi için bkz. Belgeye Çalışma Zamanında Denetim Ekleme.

Örnekler

Aşağıdaki kod örneği, yeni bir oluşturur BuildingBlockGalleryContentControl zaten belgede olan her yerel yapıtaşı Galeri için.

Belge düzeyinde özelleştirme için değildir.Bu kodu kullanmak için içine yapıştırın ThisDocument sınıfı proje ve çağrı CreateBuildingBlockControlsFromNativeControls yönteminin ThisDocument_Startup yöntemi.

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

Bir uygulama düzeyinde hedefleyen eklentisi için değil .NET Framework 4.Bu kodu kullanmak için içine yapıştırın ThisAddIn sınıfı eklenti projesi ve çağrı CreateBuildingBlockControlsFromNativeControls yönteminin ThisAddIn_Startup yöntemi.

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

Aşağıdaki kod örneği, yeni bir oluşturur BuildingBlockGalleryContentControl için kullanıcı belgeye ekler her yerel yapıtaşı Galerisi.

Belge düzeyinde özelleştirme için değildir.Bu kodu kullanmak için içine yapıştırın ThisDocument Projenizde sınıf.C# için sizin de eklemek gerekir ThisDocument_BuildingBlockContentControlAfterAdd olay işleyicisi ContentControlAfterAdd , olay ThisDocument sınıfı.

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

Bir uygulama düzeyinde hedefleyen eklentisi için değil .NET Framework 4.Bu kodu kullanmak için içine yapıştırın ThisAddIn Projenizde sınıf.Ayrıca iliştirmelisiniz ActiveDocument_BuildingBlockContentControlAfterAdd olay işleyicisi ContentControlAfterAdd etkin belgenin olay.

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 Güvenliği

Ayrıca bkz.

Başvuru

ControlCollection Arabirim

AddBuildingBlockGalleryContentControl Fazla Yük

Microsoft.Office.Tools.Word Ad Alanı

Diğer Kaynaklar

Belgeye Çalışma Zamanında Denetim Ekleme

Nasıl yapılır: Word belgeleri için içerik denetimleri ekleme