ControlCollection.AddBuildingBlockGalleryContentControl 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
AddBuildingBlockGalleryContentControl(String) |
在文件的目前選取範圍新增 BuildingBlockGalleryContentControl。 |
AddBuildingBlockGalleryContentControl(ContentControl, String) |
將新的 BuildingBlockGalleryContentControl 加入集合中。 新控制項是以已在文件中的原生內容控制項為基礎。 |
AddBuildingBlockGalleryContentControl(Range, String) |
將新的 BuildingBlockGalleryContentControl 新增在文件的指定範圍。 |
AddBuildingBlockGalleryContentControl(String)
在文件的目前選取範圍新增 BuildingBlockGalleryContentControl。
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
參數
- name
- String
新控制項的名稱。
傳回
已新增至文件的 BuildingBlockGalleryContentControl。
例外狀況
name
是 null
或長度為 0。
ControlCollection 中已具有相同名稱的控制項。
範例
下列程式代碼範例會將新的 BuildingBlockGalleryContentControl 新增至檔的開頭。 會顯示 BuildingBlockGalleryContentControl Microsoft Office Word 所提供的方程式建置組塊。
此版本適用於檔層級自定義。 若要使用此程式碼,請將它貼到專案中的 ThisDocument
類別,然後從 ThisDocument_Startup
方法呼叫 AddBuildingBlockControlAtSelection
方法。
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
此版本適用於以 .NET Framework 4 或 .NET Framework 4.5 為目標的應用程式層級載入宏。 若要使用此程式碼,請將它貼到專案中的 ThisAddIn
類別,然後從 ThisAddIn_Startup
方法呼叫 AddBuildingBlockControlAtSelection
方法。
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
備註
使用這個方法,在執行時間在檔案中的目前選取範圍加入新的 BuildingBlockGalleryContentControl 。 如需詳細資訊,請參閱 Adding Controls to Office Documents at Run Time。
適用於
AddBuildingBlockGalleryContentControl(ContentControl, String)
將新的 BuildingBlockGalleryContentControl 加入集合中。 新控制項是以已在文件中的原生內容控制項為基礎。
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
參數
- contentControl
- ContentControl
ContentControl,是新控制項的基礎。
- name
- String
新控制項的名稱。
傳回
已新增至文件的 BuildingBlockGalleryContentControl。
例外狀況
contentControl
為 null
.-或- name
為 null
或 具有零長度。
ControlCollection 中已具有相同名稱的控制項。
contentControl
不是建置組塊庫 (也就是說,Type的 contentControl
屬性沒有 Microsoft.Office.Interop.Word 值。WdContentControlType.wdContentControlBuildingBlockGallery) 。
範例
下列程式代碼範例會為每個已在檔案中的原生建置組塊庫建立新的 BuildingBlockGalleryContentControl 。
此版本適用於檔層級自定義。 若要使用此程式碼,請將它貼到專案中的 ThisDocument
類別,然後從 ThisDocument_Startup
方法呼叫 CreateBuildingBlockControlsFromNativeControls
方法。
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
此版本適用於以 .NET Framework 4 或 .NET Framework 4.5 為目標的應用程式層級載入宏。 若要使用此程式碼,請將它貼到ThisAddIn
載入宏專案中的 ThisAddIn_Startup
類別,然後從方法呼叫 CreateBuildingBlockControlsFromNativeControls
方法。
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
下列程式代碼範例會針對使用者新增至檔案的每個原生建置組塊庫建立新的 BuildingBlockGalleryContentControl 。
此版本適用於檔層級自定義。 若要使用此程式碼,請將它貼到專案中的 ThisDocument
類別。 針對 C#,您也必須將 ThisDocument_BuildingBlockContentControlAfterAdd
事件處理程式附加至 ContentControlAfterAdd 類別的 ThisDocument
事件。
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
此版本適用於以 .NET Framework 4 或 .NET Framework 4.5 為目標的應用程式層級載入宏。 若要使用此程式碼,請將它貼到專案中的 ThisAddIn
類別。 此外,您必須將 ActiveDocument_BuildingBlockContentControlAfterAdd
事件處理程式附加至 ContentControlAfterAdd 使用中檔的 事件。
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
備註
使用這個方法可新增以檔案中原生內容控制項為基礎的新 BuildingBlockGalleryContentControl 。 當您在運行時間建立 BuildingBlockGalleryContentControl 時,這非常有用,而且您想要在下一次開啟檔時重新建立相同的控件。 如需詳細資訊,請參閱 Adding Controls to Office Documents at Run Time。
適用於
AddBuildingBlockGalleryContentControl(Range, String)
將新的 BuildingBlockGalleryContentControl 新增在文件的指定範圍。
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
參數
- name
- String
新控制項的名稱。
傳回
已新增至文件的 BuildingBlockGalleryContentControl。
例外狀況
name
是 null
或長度為 0。
ControlCollection 中已具有相同名稱的控制項。
範例
下列程式代碼範例會將新的 BuildingBlockGalleryContentControl 新增至檔的開頭。 會顯示 BuildingBlockGalleryContentControl Microsoft Office Word 所提供的方程式建置組塊。
此版本適用於檔層級自定義。 若要使用此程式碼,請將它貼到專案中的 ThisDocument
類別,然後從 ThisDocument_Startup
方法呼叫 AddBuildingBlockControlAtRange
方法。
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
此版本適用於以 .NET Framework 4 或 .NET Framework 4.5 為目標的應用程式層級載入宏。 若要使用此程式碼,請將它貼到專案中的 ThisAddIn
類別,然後從 ThisAddIn_Startup
方法呼叫 AddBuildingBlockControlAtRange
方法。
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
備註
使用這個方法,在執行時間在檔案中的指定範圍新增新的 BuildingBlockGalleryContentControl 。 如需詳細資訊,請參閱 Adding Controls to Office Documents at Run Time。