SelectionEventHandler 委托

表示处理 Bookmark 控件的 SelectionChangeSelectedDeselected 事件的方法。

命名空间:  Microsoft.Office.Tools.Word
程序集:   Microsoft.Office.Tools.Word(在 Microsoft.Office.Tools.Word.dll 中)
  Microsoft.Office.Tools.Word.v4.0.Utilities(在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

语法

声明
Public Delegate Sub SelectionEventHandler ( _
    sender As Object, _
    e As SelectionEventArgs _
)
public delegate void SelectionEventHandler(
    Object sender,
    SelectionEventArgs e
)

参数

备注

当创建 SelectionEventHandler 委托时,将标识处理事件的方法。若要使该事件与事件处理程序相关联,请将该委托的一个实例添加到事件中。每当事件出现时就调用事件处理程序,直到移除该委托。有关委托的更多信息,请参见事件和委托

示例

下面的代码示例向文档中添加一个带有文本的 Bookmark 控件,然后为 Selected 事件创建一个事件处理程序。将光标移入该书签时,会显示一个消息框。

此示例针对的是文档级自定义项。

WithEvents Bookmark4 As Microsoft.Office.Tools.Word.Bookmark

Private Sub BookmarkSelected()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Bookmark4 = Me.Controls.AddBookmark(Me.Paragraphs(1).Range, _
        "Bookmark4")
    Bookmark4.Text = "This is a sample bookmark."
End Sub

Private Sub Bookmark4_Selected(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.SelectionEventArgs) _
    Handles Bookmark4.Selected
    MessageBox.Show("The selection has moved to Bookmark1.")
End Sub
Microsoft.Office.Tools.Word.Bookmark bookmark4;

private void BookmarkSelected()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    bookmark4 = this.Controls.AddBookmark(this.Paragraphs[1]
        .Range, "bookmark4");
    bookmark4.Text = "This is a sample bookmark.";
    bookmark4.Selected += new Microsoft.Office.Tools
        .Word.SelectionEventHandler(bookmark4_Selected);
}

void bookmark4_Selected(object sender, Microsoft.Office.Tools
    .Word.SelectionEventArgs e)
{
    MessageBox.Show("The selection has moved to bookmark1.");
}

请参见

参考

Microsoft.Office.Tools.Word 命名空间