ControlCollection.AddPictureContentControl-Methode (String) (2007 System)
Aktualisiert: Juli 2008
Fügt bei der aktuellen Auswahl im Dokument ein neues PictureContentControl hinzu.
Namespace: Microsoft.Office.Tools.Word
Assembly: Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)
Syntax
'Declaration
Public Function AddPictureContentControl ( _
name As String _
) As PictureContentControl
'Usage
Dim instance As ControlCollection
Dim name As String
Dim returnValue As PictureContentControl
returnValue = instance.AddPictureContentControl(name)
public PictureContentControl AddPictureContentControl(
string name
)
Parameter
name
Typ: System.StringDer Name des neuen Steuerelements.
Rückgabewert
Typ: Microsoft.Office.Tools.Word.PictureContentControl
Das PictureContentControl, das dem Dokument hinzugefügt wurde.
Ausnahmen
Ausnahme | Bedingung |
---|---|
ArgumentNullException | name ist nullNULL-Verweis (Nothing in Visual Basic) oder hat die Länge 0 (null). |
ControlNameAlreadyExistsException | Ein Steuerelement mit dem gleichen Namen ist bereits in der ControlCollection vorhanden. |
Hinweise
Verwenden Sie diese Methode, um bei der aktuellen Auswahl im Dokument zur Laufzeit ein neues PictureContentControl hinzuzufügen. Weitere Informationen finden Sie unter Hinzufügen von Steuerelementen zu Office-Dokumenten zur Laufzeit.
Beispiele
Im folgenden Codebeispiel wird am Anfang des Dokuments ein neues PictureContentControl hinzugefügt. In diesem Beispiel wird davon ausgegangen, dass sich eine Datei mit dem Namen picture.bmp im Ordner %UserProfile%\My Documents (für Windows XP und frühere Windows-Versionen) bzw. im Ordner %UserProfile%\Documents (für Windows Vista) befindet.
Diese Version bezieht sich auf eine Anpassung auf Dokumentebene. Zum Verwenden dieses Codes fügen Sie ihn in der ThisDocument-Klasse in das Projekt ein und rufen in der ThisDocument_Startup-Methode die AddPictureControlAtSelection-Methode auf.
Dim pictureControl1 As Microsoft.Office.Tools.Word.PictureContentControl
Dim bitmap1 As System.Drawing.Bitmap
Private Sub AddPictureControlAtSelection()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Me.Paragraphs(1).Range.Select()
pictureControl1 = Me.Controls.AddPictureContentControl("pictureControl1")
Dim imagePath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & _
"\picture.bmp"
bitmap1 = New System.Drawing.Bitmap(imagePath, True)
pictureControl1.Image = bitmap1
End Sub
private Microsoft.Office.Tools.Word.PictureContentControl pictureControl1;
private System.Drawing.Bitmap bitmap1;
private void AddPictureControlAtSelection()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
this.Paragraphs[1].Range.Select();
pictureControl1 = this.Controls.AddPictureContentControl("pictureControl1");
string imagePath = System.Environment.GetFolderPath(
Environment.SpecialFolder.MyDocuments) + "\\picture.bmp";
bitmap1 = new System.Drawing.Bitmap(imagePath, true);
pictureControl1.Image = bitmap1;
}
Diese Version bezieht sich auf ein Add-In auf Anwendungsebene. Zum Verwenden dieses Codes fügen Sie ihn in der ThisAddIn-Klasse in das Projekt ein und rufen in der ThisAddIn_Startup-Methode die AddPictureControlAtSelection-Methode auf.
Dim pictureControl1 As Microsoft.Office.Tools.Word.PictureContentControl
Dim bitmap1 As System.Drawing.Bitmap
Private Sub AddPictureControlAtSelection()
If Me.Application.ActiveDocument Is Nothing Then
Return
End If
Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
vstoDoc.Paragraphs(1).Range.Select()
pictureControl1 = vstoDoc.Controls.AddPictureContentControl("pictureControl1")
Dim imagePath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & _
"\picture.bmp"
bitmap1 = New System.Drawing.Bitmap(imagePath, True)
pictureControl1.Image = bitmap1
End Sub
private Microsoft.Office.Tools.Word.PictureContentControl pictureControl1;
private System.Drawing.Bitmap bitmap1;
private void AddPictureControlAtSelection()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
vstoDoc.Paragraphs[1].Range.Select();
pictureControl1 = vstoDoc.Controls.AddPictureContentControl("pictureControl1");
string imagePath = System.Environment.GetFolderPath(
Environment.SpecialFolder.MyDocuments) + "\\picture.bmp";
bitmap1 = new System.Drawing.Bitmap(imagePath, true);
pictureControl1.Image = bitmap1;
}
Berechtigungen
- Volle Vertrauenswürdigkeit für den unmittelbaren Aufrufer. Dieser Member kann von nur teilweise vertrauenswürdigem Code nicht verwendet werden. Weitere Informationen finden Sie unter Verwenden von Bibliotheken aus teilweise vertrauenswürdigem Code.
Siehe auch
Referenz
AddPictureContentControl-Überladung
Microsoft.Office.Tools.Word-Namespace
Weitere Ressourcen
Hinzufügen von Steuerelementen zu Office-Dokumenten zur Laufzeit
Hilfsmethoden für Hoststeuerelemente
Gewusst wie: Hinzufügen von Inhaltssteuerelementen zu Word-Dokumenten
Änderungsprotokoll
Date |
Versionsgeschichte |
Grund |
---|---|---|
Juli 2008 |
Version des Codebeispiels für ein Add-In auf Anwendungsebene hinzugefügt. |
SP1-Featureänderung. |