Aracılığıyla paylaş


ControlCollection.AddPictureContentControl Yöntem (ContentControl, String)

Yeni bir ekler PictureContentControl belgedeki yerel içerik denetimine dayanır.

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

Sözdizimi

'Bildirim
Function AddPictureContentControl ( _
    contentControl As ContentControl, _
    name As String _
) As PictureContentControl
PictureContentControl AddPictureContentControl(
    ContentControl contentControl,
    string name
)

Parametreler

Dönüş Değeri

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

Özel Durumlar

Exception Koşul
ArgumentNullException

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

-veya-

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

ControlNameAlreadyExistsException

Aynı ada sahip bir denetim zaten kullanılıyor ControlCollection.

ArgumentException

contentControlYapı Taşı Galerisi değil (yani, Type özelliği contentControl değeri yok Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlPicture).

Notlar

Yeni bir eklemek için bu yöntemi kullanın PictureContentControl temel alan belgedeki yerel içerik denetimine zamanında.Oluşturduğunuzda, bu yararlıdır bir PictureContentControl , çalışma zamanında ve aynı denetimi belgenin sonraki açılışında yeniden oluşturun.Daha fazla bilgi için bkz. Office Belgelerine Çalışma Zamanında Denetim Ekleme.

Örnekler

Aşağıdaki kod örneği oluşturur Yeni bir PictureContentControl belgedeki her yerel resim denetimi için.

Belge düzeyi özelleştirmesinde sürümüdür.Bu kodu kullanmak için içine yapıştırın ThisDocument sınıfı proje ve çağrı CreatePictureControlFromNativeControl yönteminden ThisDocument_Startup yöntem.

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

Private Sub CreatePictureControlsFromNativeControls()
    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.wdContentControlPicture Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.PictureContentControl = _
                Me.Controls.AddPictureContentControl(nativeControl, _
                "VSTOPictureContentControl" + count.ToString())
            pictureControls.Add(tempControl)
        End If
    Next nativeControl
End Sub
private System.Collections.Generic.List
   <Microsoft.Office.Tools.Word.PictureContentControl> pictureControls;

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

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

    foreach (Word.ContentControl nativeControl in this.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlPicture)
        {
            count++;
            Microsoft.Office.Tools.Word.PictureContentControl tempControl =
                this.Controls.AddPictureContentControl(nativeControl,
                "VSTOPictureContentControl" + count.ToString());
            pictureControls.Add(tempControl);
        }
    }
}

Bir uygulama düzeyi eklentisi hedefler de için bu sürümü olan .NET Framework 4 veya .NET Framework 4.5.Bu kodu kullanmak için içine yapıştırın ThisAddIn sınıfı proje ve çağrı CreatePictureControlFromNativeControl yönteminden ThisAddIn_Startup yöntem.

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

Private Sub CreatePictureControlsFromNativeControls()
    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.wdContentControlPicture Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.PictureContentControl = _
                vstoDoc.Controls.AddPictureContentControl(nativeControl, _
                "VSTOPictureContentControl" + count.ToString())
            pictureControls.Add(tempControl)
        End If
    Next nativeControl
End Sub
private System.Collections.Generic.List
   <Microsoft.Office.Tools.Word.PictureContentControl> pictureControls;

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

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

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

    foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlPicture)
        {
            count++;
            Microsoft.Office.Tools.Word.PictureContentControl tempControl =
                vstoDoc.Controls.AddPictureContentControl(nativeControl,
                "VSTOPictureContentControl" + count.ToString());
            pictureControls.Add(tempControl);
        }
    }
}

Aşağıdaki kod örneği oluşturur Yeni bir PictureContentControl kullanıcı belgeye ekler her yerel resim denetimi için.

Belge düzeyi özelleştirmesinde sürümüdür.Bu kodu kullanmak için içine yapıştırın ThisDocument sınıfı projenizdeki.C# [NULL]'ta, ayrıca eklemeniz gerekir ThisDocument_PictureContentControlAfterAdd olay işleyicisine ContentControlAfterAdd olayı ThisDocument sınıf.

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

    If NewContentControl.Type = Word.WdContentControlType.wdContentControlPicture Then
        Me.Controls.AddPictureContentControl(NewContentControl, _
            "PictureControl" + NewContentControl.ID)
    End If
End Sub
void ThisDocument_PictureContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlPicture)
    {
        this.Controls.AddPictureContentControl(NewContentControl,
            "PictureControl" + NewContentControl.ID);
    }
}

Bir uygulama düzeyi eklentisi hedefler de için bu sürümü olan .NET Framework 4 veya .NET Framework 4.5.Bu kodu kullanmak için içine yapıştırın ThisAddIn sınıfı projenizdeki.Ayrıca, iliştirmelisiniz ActiveDocument_PictureContentControlAfterAdd olay işleyicisine ContentControlAfterAdd etkin belgenin olay.

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

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

.NET Framework Güvenliği

Ayrıca bkz.

Başvuru

ControlCollection Arabirim

AddPictureContentControl Fazla Yük

Microsoft.Office.Tools.Word Ad Alanı

Diğer Kaynaklar

Office Belgelerine Çalışma Zamanında Denetim Ekleme

Nasıl Yapılır: Word Belgelerine İçerik Denetimleri Ekleme