Udostępnij za pośrednictwem


Metoda ControlCollection.AddGroupContentControl — (String)

Dodano nowy GroupContentControl w bieżącego zaznaczenia w dokumencie.

Przestrzeń nazw:  Microsoft.Office.Tools.Word
Zestaw:  Microsoft.Office.Tools.Word (w Microsoft.Office.Tools.Word.dll)

Składnia

'Deklaracja
Function AddGroupContentControl ( _
    name As String _
) As GroupContentControl
GroupContentControl AddGroupContentControl(
    string name
)

Parametry

Wartość zwracana

Typ: Microsoft.Office.Tools.Word.GroupContentControl
GroupContentControl Który został dodany do dokumentu.

Wyjątki

Wyjątek Warunek
ArgumentNullException

namejest nullodwołanie o wartości null (Nothing w języku Visual Basic) lub ma zerową długość.

ControlNameAlreadyExistsException

Formant o tej samej nazwie jest już pod ControlCollection.

Uwagi

Metoda ta pozwala dodać nowy GroupContentControl w bieżącego zaznaczenia w dokumencie w czasie wykonywania.Aby uzyskać więcej informacji, zobacz Dodawanie formantów do dokumentów pakietu Office w czasie wykonywania.

Przykłady

Poniższy przykład kodu dodaje się nową literę na początku dokumentu i tworzy nową GroupContentControl zawierający niniejszego ustępu.GroupContentControl Uniemożliwia użytkownikom edycję tekstu w akapicie.Aby uzyskać więcej informacji na temat korzystania z GroupContentControl do ochrony części dokumentu, zobacz Formanty zawartości.

Ta wersja jest dostosowywanie poziomie dokumentu.Aby użyć tego kodu, wklej go do ThisDocument klasy w projekcie, a wywołanie AddGroupControlAtSelection metodę z ThisDocument_Startup metoda.

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
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");
}

Ta wersja jest na poziomie aplikacji dodatek programu rozprzestrzeniającym się .NET Framework 4 lub .NET Framework 4.5.Aby użyć tego kodu, wklej go do ThisAddIn klasy w projekcie, a wywołanie AddGroupControlAtSelection metodę z ThisAddIn_Startup metoda.

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
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");
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

ControlCollection Interfejs

Przeciążenie AddGroupContentControl

Przestrzeń nazw Microsoft.Office.Tools.Word

Inne zasoby

Dodawanie formantów do dokumentów pakietu Office w czasie wykonywania

Jak: dodawanie formantów zawartości do dokumentów programu Word