Document.SelectionChange Event

Definition

Occurs when the selection changes in the document window.

public:
 event Microsoft::Office::Tools::Word::SelectionEventHandler ^ SelectionChange;
event Microsoft.Office.Tools.Word.SelectionEventHandler SelectionChange;
member this.SelectionChange : Microsoft.Office.Tools.Word.SelectionEventHandler 
Event SelectionChange As SelectionEventHandler 

Event Type

Examples

The following code example displays a message that indicates that the selection has changed whenever you change the selection within the document. This example is for an application-level add-in.

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.");
}
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

Applies to