Document.SelectionChange 事件

在文档窗口中的选定内容发生更改时发生。

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

语法

声明
Event SelectionChange As SelectionEventHandler
event SelectionEventHandler SelectionChange

示例

下面的代码示例在您更改文档中的选定内容时显示一条消息,指示选定内容已发生更改。 此示例针对的是应用程序级外接程序。

Private Sub DocumentSelectionChange()
    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    AddHandler vstoDoc.SelectionChange, AddressOf ThisDocument_SelectionChange
End Sub

Private Sub ThisDocument_SelectionChange(ByVal sender As Object, ByVal e As Microsoft.Office. _
    Tools.Word.SelectionEventArgs)
    System.Windows.Forms.MessageBox.Show("The selection in the document has changed.")
End Sub
private void DocumentSelectionChange()
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.SelectionChange += new Microsoft.Office.Tools.Word.SelectionEventHandler(ThisDocument_SelectionChange);
}

void ThisDocument_SelectionChange(object sender, Microsoft.Office.Tools.Word.SelectionEventArgs e)
{
    System.Windows.Forms.MessageBox.Show("The selection in the document has changed.");
}

.NET Framework 安全性

请参见

参考

Document 接口

Microsoft.Office.Tools.Word 命名空间