Udostępnij za pośrednictwem


Metoda ControlCollection.AddGroupContentControl — (String)

Dodaje 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 Do dokumentu dodano.

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ż w ControlCollection.

Uwagi

Ta metoda służy do dodawania nowego 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 kod dodaje się nowy ustęp na początku dokumentu, a następnie tworzy nową GroupContentControl zawierający niniejszego ustępu.GroupContentControl Uniemożliwia użytkownikom edycję tekstu w akapicie.Aby uzyskać więcej informacji o używaniu GroupContentControl ochrona innej części dokumentu, zobacz Formanty zawartości.

Ta wersja jest dla dostosowania poziomu dokumentu.Aby użyć tego kodu, wklej go do ThisDocument klasy w projekcie i wywołanie AddGroupControlAtSelection metodę z ThisDocument_Startup metody.

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 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łanie AddGroupControlAtSelection metodę z ThisAddIn_Startup metody.

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

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