ControlCollection.AddBuildingBlockGalleryContentControl Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Sobrecargas
| AddBuildingBlockGalleryContentControl(String) |
Adiciona um novo BuildingBlockGalleryContentControl na seleção atual no documento. |
| AddBuildingBlockGalleryContentControl(ContentControl, String) |
Adiciona um novo BuildingBlockGalleryContentControl à coleção. O novo controle baseia-se em um controle de conteúdo nativo que já está no documento. |
| AddBuildingBlockGalleryContentControl(Range, String) |
Adiciona um novo BuildingBlockGalleryContentControl no intervalo especificado no documento. |
AddBuildingBlockGalleryContentControl(String)
Adiciona um novo BuildingBlockGalleryContentControl na seleção atual no documento.
public Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl (string name);
Parâmetros
- name
- String
O nome do novo controle.
Retornos
O BuildingBlockGalleryContentControl adicionado ao documento.
Exceções
name é null ou tem tamanho zero.
Um controle com o mesmo nome já está no ControlCollection.
Exemplos
O exemplo de código a seguir adiciona um novo BuildingBlockGalleryContentControl ao início do documento. O BuildingBlockGalleryContentControl exibe blocos de construção da equação que são fornecidos pelo Microsoft Office Word.
Esta versão destina-se a uma personalização no nível de documento. Para usar esse código, cole-o na classe ThisDocument do projeto e chame o método AddBuildingBlockControlAtSelection no método ThisDocument_Startup.
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
Esta versão destina-se a um suplemento no nível do aplicativo que segmenta o .NET Framework 4 ou o .NET Framework 4.5. Para usar esse código, cole-o na classe ThisAddIn do projeto e chame o método AddBuildingBlockControlAtSelection no método ThisAddIn_Startup.
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
Comentários
Use este método para adicionar um novo BuildingBlockGalleryContentControl na seleção atual no documento em tempo de execução. Para obter mais informações, consulte adicionando controles a documentos do Office em tempo de execução.
Aplica-se a
AddBuildingBlockGalleryContentControl(ContentControl, String)
Adiciona um novo BuildingBlockGalleryContentControl à coleção. O novo controle baseia-se em um controle de conteúdo nativo que já está no documento.
public Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl (Microsoft.Office.Interop.Word.ContentControl contentControl, string name);
Parâmetros
- contentControl
- ContentControl
O ContentControl que é a base do novo controle.
- name
- String
O nome do novo controle.
Retornos
O BuildingBlockGalleryContentControl adicionado ao documento.
Exceções
Um controle com o mesmo nome já está no ControlCollection.
contentControl não é uma galeria de blocos de construção (ou seja, a propriedade Type de contentControl não tem o valor Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlBuildingBlockGallery).
Exemplos
O exemplo de código a seguir cria um novo BuildingBlockGalleryContentControl para cada galeria de blocos de construção nativo que já está no documento.
Esta versão destina-se a uma personalização no nível de documento. Para usar esse código, cole-o na classe ThisDocument do projeto e chame o método CreateBuildingBlockControlsFromNativeControls no método ThisDocument_Startup.
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
Esta versão destina-se a um suplemento no nível do aplicativo que segmenta o .NET Framework 4 ou o .NET Framework 4.5. Para usar esse código, Cole-o na ThisAddIn classe em seu projeto de suplemento e chame o CreateBuildingBlockControlsFromNativeControls método do ThisAddIn_Startup método.
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
O exemplo de código a seguir cria um novo BuildingBlockGalleryContentControl para cada galeria de blocos de construção nativo que o usuário adiciona ao documento.
Esta versão destina-se a uma personalização no nível de documento. Para usar esse código, cole-o na classe ThisDocument do projeto. Para o C#, você também deve anexar o ThisDocument_BuildingBlockContentControlAfterAdd manipulador de eventos ao ContentControlAfterAdd evento da 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
Esta versão destina-se a um suplemento no nível do aplicativo que segmenta o .NET Framework 4 ou o .NET Framework 4.5. Para usar esse código, cole-o na classe ThisAddIn do projeto. Além disso, você deve anexar o ActiveDocument_BuildingBlockContentControlAfterAdd manipulador de eventos ao ContentControlAfterAdd evento do documento ativo.
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
Comentários
Use esse método para adicionar um novo BuildingBlockGalleryContentControl que se baseia em um controle de conteúdo nativo no documento. Isso é útil quando você cria um BuildingBlockGalleryContentControl em tempo de execução e deseja recriar o mesmo controle na próxima vez em que o documento for aberto. Para obter mais informações, consulte adicionando controles a documentos do Office em tempo de execução.
Aplica-se a
AddBuildingBlockGalleryContentControl(Range, String)
Adiciona um novo BuildingBlockGalleryContentControl no intervalo especificado no documento.
public Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl (Microsoft.Office.Interop.Word.Range range, string name);
Parâmetros
- name
- String
O nome do novo controle.
Retornos
O BuildingBlockGalleryContentControl adicionado ao documento.
Exceções
name é null ou tem tamanho zero.
Um controle com o mesmo nome já está no ControlCollection.
Exemplos
O exemplo de código a seguir adiciona um novo BuildingBlockGalleryContentControl ao início do documento. O BuildingBlockGalleryContentControl exibe blocos de construção da equação que são fornecidos pelo Microsoft Office Word.
Esta versão destina-se a uma personalização no nível de documento. Para usar esse código, cole-o na classe ThisDocument do projeto e chame o método AddBuildingBlockControlAtRange no método ThisDocument_Startup.
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
Esta versão destina-se a um suplemento no nível do aplicativo que segmenta o .NET Framework 4 ou o .NET Framework 4.5. Para usar esse código, cole-o na classe ThisAddIn do projeto e chame o método AddBuildingBlockControlAtRange no método ThisAddIn_Startup.
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
Comentários
Use este método para adicionar um novo BuildingBlockGalleryContentControl em um intervalo especificado no documento em tempo de execução. Para obter mais informações, consulte adicionando controles a documentos do Office em tempo de execução.