Partager via


Bookmark.Collapse, méthode

Réduit un contrôle Bookmark à sa position de début ou de fin.

Espace de noms :  Microsoft.Office.Tools.Word
Assembly :  Microsoft.Office.Tools.Word (dans Microsoft.Office.Tools.Word.dll)

Syntaxe

'Déclaration
Sub Collapse ( _
    ByRef direction As Object _
)
void Collapse(
    ref Object direction
)

Paramètres

Notes

Après réduction d'un contrôle Bookmark, les points de départ et de fin sont identiques.

Si vous utilisez wdCollapseEnd pour réduire un contrôle Bookmark qui fait référence à un paragraphe entier, la plage est située après la marque de fin de paragraphe (au début du paragraphe suivant).Toutefois, vous pouvez reculer la plage d'un caractère à l'aide de la méthode MoveEnd après avoir réduit la plage du contrôle Bookmark.

Paramètres optionnels

Pour plus d'informations sur les paramètres optionnels, consultez Paramètres optionnels dans les solutions Office.

Exemples

L'exemple de code suivant ajoute un contrôle Bookmark avec du texte, puis affiche les positions de début et de fin du signet avant et après avoir réduit ce dernier.

Cet exemple illustre une personnalisation au niveau du document.

Private Sub BookmarkCollapse()

    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim Bookmark1 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Me.Paragraphs(1).Range, "Bookmark1")

    Bookmark1.Text = "This is sample bookmark text."
    MessageBox.Show("Start and end of Bookmark1 before calling Collapse: " _
        & Bookmark1.Start.ToString() & " and " & Bookmark1.End.ToString)

    Dim Direction As Object = Word.WdCollapseDirection.wdCollapseEnd
    Bookmark1.Collapse(Direction)

    MessageBox.Show("Start and end of Bookmark1 after calling Collapse: " _
        & Bookmark1.Start.ToString() & " and " & Bookmark1.End.ToString)

End Sub
private void BookmarkCollapse()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range,
        "bookmark1");

    bookmark1.Text = "This is sample bookmark text.";
    MessageBox.Show("Start and end of bookmark1 before calling Collapse: " +
        bookmark1.Start.ToString() + " and " + bookmark1.End.ToString());

    object Direction = Word.WdCollapseDirection.wdCollapseEnd;
    bookmark1.Collapse(ref Direction);

    MessageBox.Show("Start and end of bookmark1 after calling Collapse: " +
        bookmark1.Start.ToString() + " and " + bookmark1.End.ToString());
}

Sécurité .NET Framework

Voir aussi

Référence

Bookmark Interface

Microsoft.Office.Tools.Word, espace de noms