ControlCollection.AddBuildingBlockGalleryContentControl Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Overload
AddBuildingBlockGalleryContentControl(String) |
Aggiunge un nuovo BuildingBlockGalleryContentControl in corrispondenza della selezione corrente nel documento. |
AddBuildingBlockGalleryContentControl(ContentControl, String) |
Aggiunge un nuovo oggetto BuildingBlockGalleryContentControl alla raccolta. Il nuovo controllo è basato su un controllo contenuto nativo che è già nel documento. |
AddBuildingBlockGalleryContentControl(Range, String) |
Aggiunge un nuovo BuildingBlockGalleryContentControl all'intervallo specificato nel documento. |
AddBuildingBlockGalleryContentControl(String)
Aggiunge un nuovo BuildingBlockGalleryContentControl in corrispondenza della selezione corrente nel documento.
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
Parametri
- name
- String
Nome del nuovo controllo.
Restituisce
Oggetto BuildingBlockGalleryContentControl aggiunto al documento.
Eccezioni
name
è null
o ha lunghezza zero.
È già presente un controllo con lo stesso nome in ControlCollection.
Esempio
Nell'esempio di codice seguente viene aggiunto un nuovo oggetto BuildingBlockGalleryContentControl all'inizio del documento. Visualizza BuildingBlockGalleryContentControl blocchi predefiniti di equazioni forniti da Microsoft Office Word.
Questa versione è per una personalizzazione a livello di documento. Per usare questo codice, incollarlo nella ThisDocument
classe nel progetto e chiamare il AddBuildingBlockControlAtSelection
metodo dal ThisDocument_Startup
metodo.
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
Questa versione è per un componente aggiuntivo a livello di applicazione destinato a .NET Framework 4 o .NET Framework 4.5. Per usare questo codice, incollarlo nella ThisAddIn
classe nel progetto e chiamare il AddBuildingBlockControlAtSelection
metodo dal ThisAddIn_Startup
metodo.
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
Commenti
Usare questo metodo per aggiungere un nuovo BuildingBlockGalleryContentControl oggetto alla selezione corrente nel documento in fase di esecuzione. Per altre informazioni, vedere Adding Controls to Office Documents at Run Time.
Si applica a
AddBuildingBlockGalleryContentControl(ContentControl, String)
Aggiunge un nuovo oggetto BuildingBlockGalleryContentControl alla raccolta. Il nuovo controllo è basato su un controllo contenuto nativo che è già nel documento.
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
Parametri
- contentControl
- ContentControl
Oggetto ContentControl che rappresenta la base per il nuovo controllo.
- name
- String
Nome del nuovo controllo.
Restituisce
Oggetto BuildingBlockGalleryContentControl aggiunto al documento.
Eccezioni
contentControl
è .-oname
- è null
null
o ha una lunghezza zero.
È già presente un controllo con lo stesso nome in ControlCollection.
contentControl
non è una raccolta blocchi predefinito, ovvero la Type proprietà di contentControl
non ha il valore Microsoft.Office.Interop.Word. WdContentControlType.wdContentControlBuildingBlockGallery.
Esempio
Nell'esempio di codice seguente viene creato un nuovo BuildingBlockGalleryContentControl oggetto per ogni raccolta di blocchi predefiniti nativa già presente nel documento.
Questa versione è per una personalizzazione a livello di documento. Per usare questo codice, incollarlo nella ThisDocument
classe nel progetto e chiamare il CreateBuildingBlockControlsFromNativeControls
metodo dal ThisDocument_Startup
metodo.
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
Questa versione è per un componente aggiuntivo a livello di applicazione destinato a .NET Framework 4 o .NET Framework 4.5. Per usare questo codice, incollarlo ThisAddIn
nella classe nel progetto del componente aggiuntivo e chiamare il CreateBuildingBlockControlsFromNativeControls
metodo dal ThisAddIn_Startup
metodo .
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
Nell'esempio di codice seguente viene creato un nuovo BuildingBlockGalleryContentControl oggetto per ogni raccolta di blocchi predefiniti nativa che l'utente aggiunge al documento.
Questa versione è per una personalizzazione a livello di documento. Per usare questo codice, incollarlo nella ThisDocument
classe nel progetto. Per C#, è necessario collegare anche il ThisDocument_BuildingBlockContentControlAfterAdd
gestore eventi all'evento ContentControlAfterAdd della ThisDocument
classe.
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
Questa versione è per un componente aggiuntivo a livello di applicazione destinato a .NET Framework 4 o .NET Framework 4.5. Per usare questo codice, incollarlo nella ThisAddIn
classe nel progetto. È inoltre necessario collegare il ActiveDocument_BuildingBlockContentControlAfterAdd
gestore eventi all'evento ContentControlAfterAdd del documento attivo.
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
Commenti
Usare questo metodo per aggiungere un nuovo BuildingBlockGalleryContentControl oggetto basato su un controllo contenuto nativo nel documento. Ciò è utile quando si crea un oggetto BuildingBlockGalleryContentControl in fase di esecuzione e si vuole ricreare lo stesso controllo alla successiva apertura del documento. Per altre informazioni, vedere Adding Controls to Office Documents at Run Time.
Si applica a
AddBuildingBlockGalleryContentControl(Range, String)
Aggiunge un nuovo BuildingBlockGalleryContentControl all'intervallo specificato nel documento.
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
Parametri
- name
- String
Nome del nuovo controllo.
Restituisce
Oggetto BuildingBlockGalleryContentControl aggiunto al documento.
Eccezioni
name
è null
o ha lunghezza zero.
È già presente un controllo con lo stesso nome in ControlCollection.
Esempio
Nell'esempio di codice seguente viene aggiunto un nuovo oggetto BuildingBlockGalleryContentControl all'inizio del documento. Visualizza BuildingBlockGalleryContentControl blocchi predefiniti di equazioni forniti da Microsoft Office Word.
Questa versione è per una personalizzazione a livello di documento. Per usare questo codice, incollarlo nella ThisDocument
classe nel progetto e chiamare il AddBuildingBlockControlAtRange
metodo dal ThisDocument_Startup
metodo.
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
Questa versione è per un componente aggiuntivo a livello di applicazione destinato a .NET Framework 4 o .NET Framework 4.5. Per usare questo codice, incollarlo nella ThisAddIn
classe nel progetto e chiamare il AddBuildingBlockControlAtRange
metodo dal ThisAddIn_Startup
metodo.
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
Commenti
Usare questo metodo per aggiungere un nuovo BuildingBlockGalleryContentControl oggetto in un intervallo specificato nel documento in fase di esecuzione. Per altre informazioni, vedere Adding Controls to Office Documents at Run Time.