ControlCollection.AddGroupContentControl Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Przeciążenia
AddGroupContentControl(String) |
Dodaje nowy GroupContentControl element do bieżącego zaznaczenia w dokumencie. |
AddGroupContentControl(ContentControl, String) |
Dodaje nowy GroupContentControl element oparty na natywnej kontrolce zawartości w dokumencie. |
AddGroupContentControl(Range, String) |
Dodaje nowy GroupContentControl w określonym zakresie w dokumencie. |
AddGroupContentControl(String)
Dodaje nowy GroupContentControl element do bieżącego zaznaczenia w dokumencie.
public:
Microsoft::Office::Tools::Word::GroupContentControl ^ AddGroupContentControl(System::String ^ name);
public Microsoft.Office.Tools.Word.GroupContentControl AddGroupContentControl (string name);
abstract member AddGroupContentControl : string -> Microsoft.Office.Tools.Word.GroupContentControl
Public Function AddGroupContentControl (name As String) As GroupContentControl
Parametry
- name
- String
Nazwa nowego formantu.
Zwraca
Element GroupContentControl , który został dodany do dokumentu.
Wyjątki
name
jest lub null
ma zerową długość.
Kontrolka o tej samej nazwie znajduje się już w obiekcie ControlCollection.
Przykłady
Poniższy przykład kodu dodaje nowy akapit na początku dokumentu i tworzy nowy GroupContentControl , który zawiera ten akapit. Ustawienie GroupContentControl uniemożliwia użytkownikom edytowanie tekstu w akapicie. Aby uzyskać więcej informacji na temat ochrony GroupContentControl części dokumentu, zobacz Kontrolki zawartości.
Ta wersja dotyczy dostosowywania na poziomie dokumentu. Aby użyć tego kodu, wklej go do ThisDocument
klasy w projekcie i wywołaj AddGroupControlAtSelection
metodę ThisDocument_Startup
z metody .
private Microsoft.Office.Tools.Word.GroupContentControl groupControl1;
private void AddGroupControlAtSelection()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
Word.Range range1 = this.Paragraphs[1].Range;
range1.Text = "You cannot edit or change the formatting of text " +
"in this paragraph, because this paragraph is in a GroupContentControl.";
range1.Select();
groupControl1 = this.Controls.AddGroupContentControl("groupControl1");
}
Dim groupControl1 As Microsoft.Office.Tools.Word.GroupContentControl
Private Sub AddGroupControlAtSelection()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Me.Paragraphs(1).Range.Text = "You cannot edit or change the formatting of text " & _
"in this paragraph, because this paragraph is in a GroupContentControl."
Me.Paragraphs(1).Range.Select()
groupControl1 = Me.Controls.AddGroupContentControl("groupControl1")
End Sub
Ta wersja jest przeznaczona dla dodatku na poziomie aplikacji, który jest przeznaczony dla .NET Framework 4 lub .NET Framework 4.5. Aby użyć tego kodu, wklej go do ThisAddIn
klasy w projekcie i wywołaj AddGroupControlAtSelection
metodę ThisAddIn_Startup
z metody .
private Microsoft.Office.Tools.Word.GroupContentControl groupControl1;
private void AddGroupControlAtSelection()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
Word.Range range1 = vstoDoc.Paragraphs[1].Range;
range1.Text = "You cannot edit or change the formatting of text " +
"in this paragraph, because this paragraph is in a GroupContentControl.";
range1.Select();
groupControl1 = vstoDoc.Controls.AddGroupContentControl("groupControl1");
}
Dim groupControl1 As Microsoft.Office.Tools.Word.GroupContentControl
Private Sub AddGroupControlAtSelection()
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.Text = "You cannot edit or change the formatting of text " & _
"in this paragraph, because this paragraph is in a GroupContentControl."
vstoDoc.Paragraphs(1).Range.Select()
groupControl1 = vstoDoc.Controls.AddGroupContentControl("groupControl1")
End Sub
Uwagi
Użyj tej metody, aby dodać nowy GroupContentControl element w bieżącym zaznaczeniu w dokumencie w czasie wykonywania. Aby uzyskać więcej informacji, zobacz Dodawanie kontrolek do dokumentów pakietu Office w czasie wykonywania.
Dotyczy
AddGroupContentControl(ContentControl, String)
Dodaje nowy GroupContentControl element oparty na natywnej kontrolce zawartości w dokumencie.
public:
Microsoft::Office::Tools::Word::GroupContentControl ^ AddGroupContentControl(Microsoft::Office::Interop::Word::ContentControl ^ contentControl, System::String ^ name);
public Microsoft.Office.Tools.Word.GroupContentControl AddGroupContentControl (Microsoft.Office.Interop.Word.ContentControl contentControl, string name);
abstract member AddGroupContentControl : Microsoft.Office.Interop.Word.ContentControl * string -> Microsoft.Office.Tools.Word.GroupContentControl
Public Function AddGroupContentControl (contentControl As ContentControl, name As String) As GroupContentControl
Parametry
- contentControl
- ContentControl
Jest ContentControl to podstawa nowej kontrolki.
- name
- String
Nazwa nowego formantu.
Zwraca
Element GroupContentControl , który został dodany do dokumentu.
Wyjątki
contentControl
jest null
.-or- name
lub null
ma zerową długość.
Kontrolka o tej samej nazwie znajduje się już w obiekcie ControlCollection.
contentControl
nie jest galerią bloków contentControl
konstrukcyjnych (czyli Type właściwość nie ma wartości Microsoft.Office.Interop.Word. WdContentControlType.wdContentControlGroup).
Przykłady
Poniższy przykład kodu tworzy nowy GroupContentControl dla każdej natywnej kontrolki grupy, która znajduje się w dokumencie.
Ta wersja dotyczy dostosowywania na poziomie dokumentu. Aby użyć tego kodu, wklej go do ThisDocument
klasy w projekcie i wywołaj CreateGroupControlsFromNativeControls
metodę ThisDocument_Startup
z metody .
private System.Collections.Generic.List
<Microsoft.Office.Tools.Word.GroupContentControl> groupControls;
private void CreateGroupControlsFromNativeControls()
{
if (this.ContentControls.Count <= 0)
return;
groupControls = new System.Collections.Generic.List
<Microsoft.Office.Tools.Word.GroupContentControl>();
int count = 0;
foreach (Word.ContentControl nativeControl in this.ContentControls)
{
if (nativeControl.Type == Word.WdContentControlType.wdContentControlGroup)
{
count++;
Microsoft.Office.Tools.Word.GroupContentControl tempControl =
this.Controls.AddGroupContentControl(nativeControl,
"VSTOGroupControl" + count.ToString());
groupControls.Add(tempControl);
}
}
}
Private groupControls As New System.Collections.Generic.List _
(Of Microsoft.Office.Tools.Word.GroupContentControl)
Private Sub CreateGroupControlsFromNativeControls()
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.wdContentControlGroup Then
count += 1
Dim tempControl As Microsoft.Office.Tools.Word.GroupContentControl = _
Me.Controls.AddGroupContentControl(nativeControl, _
"VSTOGroupContentControl" + count.ToString())
groupControls.Add(tempControl)
End If
Next nativeControl
End Sub
Ta wersja jest przeznaczona dla dodatku na poziomie aplikacji, który jest przeznaczony dla .NET Framework 4 lub .NET Framework 4.5. Aby użyć tego kodu, wklej go do ThisAddIn
klasy w projekcie i wywołaj CreateGroupControlsFromNativeControls
metodę ThisAddIn_Startup
z metody .
private System.Collections.Generic.List
<Microsoft.Office.Tools.Word.GroupContentControl> groupControls;
private void CreateGroupControlsFromNativeControls()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
if (vstoDoc.ContentControls.Count <= 0)
return;
groupControls = new System.Collections.Generic.List
<Microsoft.Office.Tools.Word.GroupContentControl>();
int count = 0;
foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
{
if (nativeControl.Type == Word.WdContentControlType.wdContentControlGroup)
{
count++;
Microsoft.Office.Tools.Word.GroupContentControl tempControl =
vstoDoc.Controls.AddGroupContentControl(nativeControl,
"VSTOGroupControl" + count.ToString());
groupControls.Add(tempControl);
}
}
}
Private groupControls As New System.Collections.Generic.List _
(Of Microsoft.Office.Tools.Word.GroupContentControl)
Private Sub CreateGroupControlsFromNativeControls()
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.wdContentControlGroup Then
count += 1
Dim tempControl As Microsoft.Office.Tools.Word.GroupContentControl = _
vstoDoc.Controls.AddGroupContentControl(nativeControl, _
"VSTOGroupContentControl" + count.ToString())
groupControls.Add(tempControl)
End If
Next nativeControl
End Sub
Poniższy przykład kodu tworzy nowy GroupContentControl dla każdej natywnej kontrolki grupy, którą użytkownik dodaje do dokumentu.
Ta wersja dotyczy dostosowywania na poziomie dokumentu. Aby użyć tego kodu, wklej go do ThisDocument
klasy w projekcie. W przypadku języka C#należy również dołączyć ThisDocument_GroupContentControlAfterAdd
program obsługi zdarzeń do ContentControlAfterAdd zdarzenia ThisDocument
klasy.
void ThisDocument_GroupContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
if (NewContentControl.Type == Word.WdContentControlType.wdContentControlGroup)
{
this.Controls.AddGroupContentControl(NewContentControl,
"GroupControl" + NewContentControl.ID);
}
}
Private Sub ThisDocument_GroupContentControlAfterAdd(ByVal NewContentControl As Word.ContentControl, _
ByVal InUndoRedo As Boolean) Handles Me.ContentControlAfterAdd
If NewContentControl.Type = Word.WdContentControlType.wdContentControlGroup Then
Me.Controls.AddGroupContentControl(NewContentControl, _
"GroupControl" + NewContentControl.ID)
End If
End Sub
Ta wersja jest przeznaczona dla dodatku na poziomie aplikacji, który jest przeznaczony dla .NET Framework 4 lub .NET Framework 4.5. Aby użyć tego kodu, wklej go do ThisAddIn
klasy w projekcie. Ponadto należy dołączyć procedurę ActiveDocument_GroupContentControlAfterAdd
obsługi zdarzeń do ContentControlAfterAdd zdarzenia aktywnego dokumentu.
void ActiveDocument_GroupContentControlAfterAdd(
Word.ContentControl NewContentControl, bool InUndoRedo)
{
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
if (NewContentControl.Type == Word.WdContentControlType.wdContentControlGroup)
{
vstoDoc.Controls.AddGroupContentControl(NewContentControl,
"GroupControl" + NewContentControl.ID);
}
}
Private Sub ActiveDocument_GroupContentControlAfterAdd( _
ByVal NewContentControl As Word.ContentControl, _
ByVal InUndoRedo As Boolean)
Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
If NewContentControl.Type = Word.WdContentControlType. _
wdContentControlGroup Then
vstoDoc.Controls.AddGroupContentControl(NewContentControl, _
"GroupControl" + NewContentControl.ID)
End If
End Sub
Uwagi
Użyj tej metody, aby dodać nową GroupContentControl , która jest oparta na natywnej kontrolce zawartości w dokumencie w czasie wykonywania. Jest to przydatne podczas tworzenia GroupContentControl w czasie wykonywania i chcesz ponownie utworzyć tę samą kontrolkę przy następnym otwarciu dokumentu. Aby uzyskać więcej informacji, zobacz Dodawanie kontrolek do dokumentów pakietu Office w czasie wykonywania.
Dotyczy
AddGroupContentControl(Range, String)
Dodaje nowy GroupContentControl w określonym zakresie w dokumencie.
public:
Microsoft::Office::Tools::Word::GroupContentControl ^ AddGroupContentControl(Microsoft::Office::Interop::Word::Range ^ range, System::String ^ name);
public Microsoft.Office.Tools.Word.GroupContentControl AddGroupContentControl (Microsoft.Office.Interop.Word.Range range, string name);
abstract member AddGroupContentControl : Microsoft.Office.Interop.Word.Range * string -> Microsoft.Office.Tools.Word.GroupContentControl
Public Function AddGroupContentControl (range As Range, name As String) As GroupContentControl
Parametry
- name
- String
Nazwa nowego formantu.
Zwraca
Element GroupContentControl , który został dodany do dokumentu.
Wyjątki
name
jest lub null
ma zerową długość.
Kontrolka o tej samej nazwie znajduje się już w obiekcie ControlCollection.
Przykłady
Poniższy przykład kodu dodaje nowy akapit na początku dokumentu i tworzy obiekt GroupContentControl zawierający ten akapit. Ustawienie GroupContentControl uniemożliwia użytkownikom edytowanie tekstu w akapicie. Aby uzyskać więcej informacji na temat ochrony GroupContentControl części dokumentu, zobacz Kontrolki zawartości.
Ta wersja dotyczy dostosowywania na poziomie dokumentu. Aby użyć tego kodu, wklej go do ThisDocument
klasy w projekcie i wywołaj AddGroupControlAtRange
metodę ThisDocument_Startup
z metody .
private Microsoft.Office.Tools.Word.GroupContentControl groupControl2;
private void AddGroupControlAtRange()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
Word.Range range1 = this.Paragraphs[1].Range;
range1.Text = "You cannot edit or change the formatting of text " +
"in this paragraph, because this paragraph is in a GroupContentControl.";
range1.Select();
groupControl2 = this.Controls.AddGroupContentControl(range1, "groupControl2");
}
Dim groupControl2 As Microsoft.Office.Tools.Word.GroupContentControl
Private Sub AddGroupControlAtRange()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Dim range1 As Word.Range = Me.Paragraphs(1).Range
range1.Text = "You cannot edit or change the formatting of text " & _
"in this paragraph, because this paragraph is in a GroupContentControl."
range1.Select()
groupControl2 = Me.Controls.AddGroupContentControl(range1, "groupControl2")
End Sub
Ta wersja jest przeznaczona dla dodatku na poziomie aplikacji, który jest przeznaczony dla .NET Framework 4 lub .NET Framework 4.5. Aby użyć tego kodu, wklej go do ThisAddIn
klasy w projekcie i wywołaj AddGroupControlAtRange
metodę ThisAddIn_Startup
z metody .
private Microsoft.Office.Tools.Word.GroupContentControl groupControl2;
private void AddGroupControlAtRange()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
Word.Range range1 = vstoDoc.Paragraphs[1].Range;
range1.Text = "You cannot edit or change the formatting of text " +
"in this paragraph, because this paragraph is in a GroupContentControl.";
range1.Select();
groupControl2 = vstoDoc.Controls.AddGroupContentControl(range1, "groupControl2");
}
Dim groupControl2 As Microsoft.Office.Tools.Word.GroupContentControl
Private Sub AddGroupControlAtRange()
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()
Dim range1 As Word.Range = vstoDoc.Paragraphs(1).Range
range1.Text = "You cannot edit or change the formatting of text " & _
"in this paragraph, because this paragraph is in a GroupContentControl."
range1.Select()
groupControl2 = vstoDoc.Controls.AddGroupContentControl(range1, "groupControl2")
End Sub
Uwagi
Użyj tej metody, aby dodać nowy GroupContentControl w określonym zakresie w dokumencie w czasie wykonywania. Aby uzyskać więcej informacji, zobacz Dodawanie kontrolek do dokumentów pakietu Office w czasie wykonywania.