Share via


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 命名空間