Document.SelectionChange Event (2007 System)
Occurs when the selection changes in the document window.
Namespace: Microsoft.Office.Tools.Word
Assembly: Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)
Syntax
'Declaration
Public Event SelectionChange As SelectionEventHandler
'Usage
Dim instance As Document
Dim handler As SelectionEventHandler
AddHandler instance.SelectionChange, handler
public event SelectionEventHandler SelectionChange
public:
event SelectionEventHandler^ SelectionChange {
void add (SelectionEventHandler^ value);
void remove (SelectionEventHandler^ value);
}
JScript does not support events.
Examples
The following code example displays a message that indicates that the selection has changed whenever you change the selection within the document.
This version is for a document-level customization.
Private Sub DocumentSelectionChange()
AddHandler Me.SelectionChange, AddressOf ThisDocument_SelectionChange
End Sub
Private Sub ThisDocument_SelectionChange(ByVal sender As Object, ByVal e As Microsoft.Office. _
Tools.Word.SelectionEventArgs)
MessageBox.Show("The selection in the document has changed.")
End Sub
private void DocumentSelectionChange()
{
this.SelectionChange += new Microsoft.Office.Tools.Word.SelectionEventHandler(ThisDocument_SelectionChange);
}
void ThisDocument_SelectionChange(object sender, Microsoft.Office.Tools.Word.SelectionEventArgs e)
{
MessageBox.Show("The selection in the document has changed.");
}
This version is for an application-level add-in.
Private Sub DocumentSelectionChange()
Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
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 = this.Application.ActiveDocument.GetVstoObject();
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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.Office.Tools.Word Namespace
Change History
Date |
History |
Reason |
---|---|---|
July 2008 |
Added a version of the code example for an application-level add-in. |
SP1 feature change. |