ControlCollection.AddBuildingBlockGalleryContentControl Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Überlädt
AddBuildingBlockGalleryContentControl(String) |
Fügt bei der aktuellen Auswahl im Dokument ein neues BuildingBlockGalleryContentControl hinzu. |
AddBuildingBlockGalleryContentControl(ContentControl, String) |
Fügt der Auflistung eine neue BuildingBlockGalleryContentControl-Instanz hinzu. Das neue Steuerelement basiert auf einem nativen Inhaltssteuerelement, das bereits im Dokument enthalten ist. |
AddBuildingBlockGalleryContentControl(Range, String) |
Fügt ein neues BuildingBlockGalleryContentControl im angegebenen Bereich im Dokument hinzu. |
AddBuildingBlockGalleryContentControl(String)
Fügt bei der aktuellen Auswahl im Dokument ein neues BuildingBlockGalleryContentControl hinzu.
public:
Microsoft::Office::Tools::Word::BuildingBlockGalleryContentControl ^ AddBuildingBlockGalleryContentControl(System::String ^ name);
public Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl (string name);
abstract member AddBuildingBlockGalleryContentControl : string -> Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
Public Function AddBuildingBlockGalleryContentControl (name As String) As BuildingBlockGalleryContentControl
Parameter
- name
- String
Der Name des neuen Steuerelements.
Gibt zurück
Das BuildingBlockGalleryContentControl, das dem Dokument hinzugefügt wurde.
Ausnahmen
name
ist null
oder hat die Länge 0 (null).
Ein Steuerelement mit dem gleichen Namen ist bereits in der ControlCollection enthalten.
Beispiele
Im folgenden Codebeispiel wird am Anfang des Dokuments ein neues BuildingBlockGalleryContentControl hinzugefügt. Zeigt BuildingBlockGalleryContentControl Formelbausteine an, die von Microsoft Office Word bereitgestellt werden.
Diese Version ist für eine Anpassung auf Dokumentebene vorgesehen. Um diesen Code zu verwenden, fügen Sie ihn in die ThisDocument
-Klasse in Ihrem Projekt ein, und rufen Sie die AddBuildingBlockControlAtSelection
-Methode aus der ThisDocument_Startup
-Methode auf.
private Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl buildingBlockControl1;
private void AddBuildingBlockControlAtSelection()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
this.Paragraphs[1].Range.Select();
buildingBlockControl1 = this.Controls.AddBuildingBlockGalleryContentControl(
"buildingBlockControl1");
buildingBlockControl1.PlaceholderText = "Choose an equation";
buildingBlockControl1.BuildingBlockCategory = "Built-In";
buildingBlockControl1.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations;
}
Dim buildingBlockGalleryControl1 As Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
Private Sub AddBuildingBlockGalleryControlAtSelection()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Me.Paragraphs(1).Range.Select()
buildingBlockGalleryControl1 = Me.Controls.AddBuildingBlockGalleryContentControl( _
"buildingBlockGalleryControl1")
With buildingBlockGalleryControl1
.PlaceholderText = "Choose an equation"
.BuildingBlockCategory = "Built-In"
.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations
End With
End Sub
Diese Version ist für ein Add-In auf Anwendungsebene vorgesehen, das auf die .NET Framework 4 oder die .NET Framework 4.5 ausgerichtet ist. Um diesen Code zu verwenden, fügen Sie ihn in die ThisAddIn
-Klasse in Ihrem Projekt ein, und rufen Sie die AddBuildingBlockControlAtSelection
-Methode aus der ThisAddIn_Startup
-Methode auf.
private Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl buildingBlockControl1;
private void AddBuildingBlockControlAtSelection()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
vstoDoc.Paragraphs[1].Range.Select();
buildingBlockControl1 = vstoDoc.Controls.AddBuildingBlockGalleryContentControl(
"buildingBlockControl1");
buildingBlockControl1.PlaceholderText = "Choose an equation";
buildingBlockControl1.BuildingBlockCategory = "Built-In";
buildingBlockControl1.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations;
}
Dim buildingBlockGalleryControl1 As BuildingBlockGalleryContentControl
Private Sub AddBuildingBlockGalleryControlAtSelection()
If Me.Application.ActiveDocument Is Nothing Then
Return
End If
Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
vstoDoc.Paragraphs(1).Range.Select()
buildingBlockGalleryControl1 = vstoDoc.Controls.AddBuildingBlockGalleryContentControl( _
"buildingBlockGalleryControl1")
With buildingBlockGalleryControl1
.PlaceholderText = "Choose an equation"
.BuildingBlockCategory = "Built-In"
.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations
End With
End Sub
Hinweise
Verwenden Sie diese Methode, um zur Laufzeit ein neues BuildingBlockGalleryContentControl bei der aktuellen Auswahl im Dokument hinzuzufügen. Weitere Informationen finden Sie unter Adding Controls to Office Documents at Run Time.
Gilt für:
AddBuildingBlockGalleryContentControl(ContentControl, String)
Fügt der Auflistung eine neue BuildingBlockGalleryContentControl-Instanz hinzu. Das neue Steuerelement basiert auf einem nativen Inhaltssteuerelement, das bereits im Dokument enthalten ist.
public:
Microsoft::Office::Tools::Word::BuildingBlockGalleryContentControl ^ AddBuildingBlockGalleryContentControl(Microsoft::Office::Interop::Word::ContentControl ^ contentControl, System::String ^ name);
public Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl (Microsoft.Office.Interop.Word.ContentControl contentControl, string name);
abstract member AddBuildingBlockGalleryContentControl : Microsoft.Office.Interop.Word.ContentControl * string -> Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
Public Function AddBuildingBlockGalleryContentControl (contentControl As ContentControl, name As String) As BuildingBlockGalleryContentControl
Parameter
- contentControl
- ContentControl
Das ContentControl, das die Grundlage für das neue Steuerelement ist.
- name
- String
Der Name des neuen Steuerelements.
Gibt zurück
Das BuildingBlockGalleryContentControl, das dem Dokument hinzugefügt wurde.
Ausnahmen
contentControl
ist null
.-or- name
ist null
oder hat die Länge null.
Ein Steuerelement mit dem gleichen Namen ist bereits in der ControlCollection enthalten.
contentControl
ist kein Bausteinkatalog (d. h. die Type -Eigenschaft von contentControl
hat nicht den Wert Microsoft.Office.Interop.Word. WdContentControlType.wdContentControlBuildingBlockGallery).
Beispiele
Im folgenden Codebeispiel wird ein neues BuildingBlockGalleryContentControl für jeden nativen Bausteinkatalog erstellt, der bereits im Dokument enthalten ist.
Diese Version ist für eine Anpassung auf Dokumentebene vorgesehen. Um diesen Code zu verwenden, fügen Sie ihn in die ThisDocument
-Klasse in Ihrem Projekt ein, und rufen Sie die CreateBuildingBlockControlsFromNativeControls
-Methode aus der ThisDocument_Startup
-Methode auf.
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);
}
}
}
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
Diese Version ist für ein Add-In auf Anwendungsebene vorgesehen, das auf die .NET Framework 4 oder die .NET Framework 4.5 ausgerichtet ist. Um diesen Code zu verwenden, fügen Sie ihn in die ThisAddIn
-Klasse in Ihrem Add-In-Projekt ein, und rufen Sie die CreateBuildingBlockControlsFromNativeControls
-Methode aus der ThisAddIn_Startup
-Methode auf.
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);
}
}
}
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
Im folgenden Codebeispiel wird ein neues BuildingBlockGalleryContentControl für jeden nativen Bausteinkatalog erstellt, den der Benutzer dem Dokument hinzufügt.
Diese Version ist für eine Anpassung auf Dokumentebene vorgesehen. Um diesen Code zu verwenden, fügen Sie ihn in die ThisDocument
-Klasse in Ihrem Projekt ein. Für C# müssen Sie den ThisDocument_BuildingBlockContentControlAfterAdd
Ereignishandler auch an das ContentControlAfterAdd Ereignis der ThisDocument
-Klasse anfügen.
void ThisDocument_BuildingBlockContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
if (NewContentControl.Type == Word.WdContentControlType.wdContentControlBuildingBlockGallery)
{
this.Controls.AddBuildingBlockGalleryContentControl(NewContentControl,
"BuildingBlockControl" + NewContentControl.ID);
}
}
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
Diese Version ist für ein Add-In auf Anwendungsebene vorgesehen, das auf die .NET Framework 4 oder die .NET Framework 4.5 ausgerichtet ist. Um diesen Code zu verwenden, fügen Sie ihn in die ThisAddIn
-Klasse in Ihrem Projekt ein. Außerdem müssen Sie den ActiveDocument_BuildingBlockContentControlAfterAdd
Ereignishandler an das ContentControlAfterAdd Ereignis des aktiven Dokuments anfügen.
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);
}
}
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
Hinweise
Verwenden Sie diese Methode, um ein neues BuildingBlockGalleryContentControl hinzuzufügen, das auf einem nativen Inhaltssteuerelement im Dokument basiert. Dies ist nützlich, wenn Sie ein BuildingBlockGalleryContentControl zur Laufzeit erstellen und dasselbe Steuerelement beim nächsten Öffnen des Dokuments neu erstellen möchten. Weitere Informationen finden Sie unter Adding Controls to Office Documents at Run Time.
Gilt für:
AddBuildingBlockGalleryContentControl(Range, String)
Fügt ein neues BuildingBlockGalleryContentControl im angegebenen Bereich im Dokument hinzu.
public:
Microsoft::Office::Tools::Word::BuildingBlockGalleryContentControl ^ AddBuildingBlockGalleryContentControl(Microsoft::Office::Interop::Word::Range ^ range, System::String ^ name);
public Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl (Microsoft.Office.Interop.Word.Range range, string name);
abstract member AddBuildingBlockGalleryContentControl : Microsoft.Office.Interop.Word.Range * string -> Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
Public Function AddBuildingBlockGalleryContentControl (range As Range, name As String) As BuildingBlockGalleryContentControl
Parameter
- name
- String
Der Name des neuen Steuerelements.
Gibt zurück
Das BuildingBlockGalleryContentControl, das dem Dokument hinzugefügt wurde.
Ausnahmen
name
ist null
oder hat die Länge 0 (null).
Ein Steuerelement mit dem gleichen Namen ist bereits in der ControlCollection enthalten.
Beispiele
Im folgenden Codebeispiel wird am Anfang des Dokuments ein neues BuildingBlockGalleryContentControl hinzugefügt. Zeigt BuildingBlockGalleryContentControl Formelbausteine an, die von Microsoft Office Word bereitgestellt werden.
Diese Version ist für eine Anpassung auf Dokumentebene vorgesehen. Um diesen Code zu verwenden, fügen Sie ihn in die ThisDocument
-Klasse in Ihrem Projekt ein, und rufen Sie die AddBuildingBlockControlAtRange
-Methode aus der ThisDocument_Startup
-Methode auf.
private Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl buildingBlockControl2;
private void AddBuildingBlockControlAtRange()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
buildingBlockControl2 = this.Controls.AddBuildingBlockGalleryContentControl(
this.Paragraphs[1].Range, "buildingBlockControl2");
buildingBlockControl2.PlaceholderText = "Choose an equation";
buildingBlockControl2.BuildingBlockCategory = "Built-In";
buildingBlockControl2.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations;
}
Dim buildingBlockGalleryControl2 As Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
Private Sub AddBuildingBlockGalleryControlAtRange()
Me.Paragraphs(1).Range.InsertParagraphBefore()
buildingBlockGalleryControl2 = Me.Controls.AddBuildingBlockGalleryContentControl( _
Me.Paragraphs(1).Range, "buildingBlockGalleryControl2")
With buildingBlockGalleryControl2
.PlaceholderText = "Choose an equation"
.BuildingBlockCategory = "Built-In"
.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations
End With
End Sub
Diese Version ist für ein Add-In auf Anwendungsebene vorgesehen, das auf die .NET Framework 4 oder die .NET Framework 4.5 ausgerichtet ist. Um diesen Code zu verwenden, fügen Sie ihn in die ThisAddIn
-Klasse in Ihrem Projekt ein, und rufen Sie die AddBuildingBlockControlAtRange
-Methode aus der ThisAddIn_Startup
-Methode auf.
private Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl buildingBlockControl2;
private void AddBuildingBlockControlAtRange()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
buildingBlockControl2 = vstoDoc.Controls.AddBuildingBlockGalleryContentControl(
vstoDoc.Paragraphs[1].Range, "buildingBlockControl2");
buildingBlockControl2.PlaceholderText = "Choose an equation";
buildingBlockControl2.BuildingBlockCategory = "Built-In";
buildingBlockControl2.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations;
}
Dim buildingBlockGalleryControl2 As BuildingBlockGalleryContentControl
Private Sub AddBuildingBlockGalleryControlAtRange()
If Me.Application.ActiveDocument Is Nothing Then
Return
End If
Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
buildingBlockGalleryControl2 = vstoDoc.Controls.AddBuildingBlockGalleryContentControl( _
vstoDoc.Paragraphs(1).Range, "buildingBlockGalleryControl2")
With buildingBlockGalleryControl2
.PlaceholderText = "Choose an equation"
.BuildingBlockCategory = "Built-In"
.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations
End With
End Sub
Hinweise
Verwenden Sie diese Methode, um zur Laufzeit ein neues BuildingBlockGalleryContentControl in einem angegebenen Bereich im Dokument hinzuzufügen. Weitere Informationen finden Sie unter Adding Controls to Office Documents at Run Time.