共用方式為


Bookmark.ShapeRange 屬性

取得 ShapeRange 集合,表示在 Bookmark 控制項中的所有 Shape 物件。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word (在 Microsoft.Office.Tools.Word.dll 中)

語法

'宣告
ReadOnly Property ShapeRange As ShapeRange
ShapeRange ShapeRange { get; }

屬性值

型別:Microsoft.Office.Interop.Word.ShapeRange
ShapeRange 集合,表示在 Bookmark 控制項中的所有 Shape 物件。

備註

圖案範圍可包括繪圖、形狀、圖片、OLE 物件、ActiveX 控制項、文字物件,以及圖說文字。

範例

下列程式碼範例將有文字的 Bookmark 控制項加入至文件,然後在建立文字方塊時使用書籤的垂直和水平位置。然後便會在訊息方塊中顯示書籤內的 ShapeRange 名稱。

這是示範文件層級自訂的範例。

Private Sub BookmarkShapeRange()

    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."

    Dim vertical As Single = Bookmark1.Information(Microsoft.Office _
        .Interop.Word.WdInformation.wdVerticalPositionRelativeToPage)
    Dim horizontal As Single = Bookmark1.Information(Microsoft.Office _
        .Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage)

    Dim shape As Word.Shape = Me.Shapes.AddTextbox(Microsoft.Office.Core _
        .MsoTextOrientation.msoTextOrientationHorizontal, vertical, _
        horizontal, 50, 50)

    MessageBox.Show(Bookmark1.ShapeRange.Name.ToString)

End Sub
private void BookmarkShapeRange()
{
    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.";

    object myRange = bookmark1.Range;
    object vertical = bookmark1.Information[Microsoft.Office
        .Interop.Word.WdInformation.wdVerticalPositionRelativeToPage];
    object horizontal = bookmark1.Information[Microsoft.Office
        .Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage];

    Word.Shape shape = this.Shapes.AddTextbox(Microsoft.Office.Core
        .MsoTextOrientation.msoTextOrientationHorizontal, (float)vertical, 
        (float)horizontal, 50, 50, ref missing);

    MessageBox.Show(bookmark1.ShapeRange.Name.ToString());
}

.NET Framework 安全性

請參閱

參考

Bookmark 介面

Microsoft.Office.Tools.Word 命名空間