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 (string name);
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 BuildingBlockGalleryContentControl am Anfang des Dokuments ein neues hinzugefügt. Das BuildingBlockGalleryContentControl zeigt Gleichung-Bausteine an, die von Microsoft Office Word bereitgestellt werden.
Diese Version ist für eine Anpassung auf Dokument Ebene vorgesehen. Um diesen Code zu verwenden, fügen Sie ihn in die ThisDocument -Klasse in Ihrem Projekt ein, und nennen Sie die- AddBuildingBlockControlAtSelection Methode von der- ThisDocument_Startup Methode.
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 bezieht sich auf ein Add-In auf Anwendungsebene, das auf .NET Framework 4 oder .NET Framework 4.5 abzielt. Um diesen Code zu verwenden, fügen Sie ihn in die ThisAddIn -Klasse in Ihrem Projekt ein, und nennen Sie die- AddBuildingBlockControlAtSelection Methode von der- ThisAddIn_Startup Methode.
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 BuildingBlockGalleryContentControl Laufzeit einen neuen an 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, string name);
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
Ein Steuerelement mit dem gleichen Namen ist bereits in der ControlCollection enthalten.
contentControl ist kein Bausteinkatalog (d.h. die Type-Eigenschaft von contentControl weist nicht den Wert Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlBuildingBlockGallery auf).
Beispiele
Im folgenden Codebeispiel wird ein neues BuildingBlockGalleryContentControl für jeden systemeigenen Baustein Katalog erstellt, der bereits im Dokument enthalten ist.
Diese Version ist für eine Anpassung auf Dokument Ebene vorgesehen. Um diesen Code zu verwenden, fügen Sie ihn in die ThisDocument -Klasse in Ihrem Projekt ein, und nennen Sie die- CreateBuildingBlockControlsFromNativeControls Methode von der- ThisDocument_Startup Methode.
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 bezieht sich auf ein Add-In auf Anwendungsebene, das auf .NET Framework 4 oder .NET Framework 4.5 abzielt. Wenn Sie diesen Code verwenden möchten, fügen Sie ihn in die ThisAddIn -Klasse in Ihrem Add-in-Projekt ein, und nennen Sie die- CreateBuildingBlockControlsFromNativeControls Methode aus der- ThisAddIn_Startup Methode.
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 jede Native Baustein Galerie erstellt, die dem Dokument hinzugefügt wird.
Diese Version ist für eine Anpassung auf Dokument Ebene vorgesehen. Wenn Sie diesen Code verwenden möchten, fügen Sie ihn in die- ThisDocument Klasse in Ihrem Projekt ein. Für c# müssen Sie auch den- ThisDocument_BuildingBlockContentControlAfterAdd Ereignishandler 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 bezieht sich auf ein Add-In auf Anwendungsebene, das auf .NET Framework 4 oder .NET Framework 4.5 abzielt. Wenn Sie diesen Code verwenden möchten, 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 hinzuzufügen BuildingBlockGalleryContentControl , das auf einem systemeigenen Inhalts Steuerelement im Dokument basiert. Dies ist hilfreich, wenn Sie einen BuildingBlockGalleryContentControl zur Laufzeit erstellen und das gleiche 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, string name);
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 BuildingBlockGalleryContentControl am Anfang des Dokuments ein neues hinzugefügt. Das BuildingBlockGalleryContentControl zeigt Gleichung-Bausteine an, die von Microsoft Office Word bereitgestellt werden.
Diese Version ist für eine Anpassung auf Dokument Ebene vorgesehen. Um diesen Code zu verwenden, fügen Sie ihn in die ThisDocument -Klasse in Ihrem Projekt ein, und nennen Sie die- AddBuildingBlockControlAtRange Methode von der- ThisDocument_Startup Methode.
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 bezieht sich auf ein Add-In auf Anwendungsebene, das auf .NET Framework 4 oder .NET Framework 4.5 abzielt. Um diesen Code zu verwenden, fügen Sie ihn in die ThisAddIn -Klasse in Ihrem Projekt ein, und nennen Sie die- AddBuildingBlockControlAtRange Methode von der- ThisAddIn_Startup Methode.
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 einen neuen zu BuildingBlockGalleryContentControl einem angegebenen Bereich im Dokument hinzuzufügen. Weitere Informationen finden Sie unter Adding Controls to Office Documents at Run Time.