Partager via


ContextChangeEventHandler Delegate

Definition

Represents the method that will handle the Select, Deselect, ContextEnter and ContextLeave events of an XMLNode object and the ContextEnter, ContextLeave, Select, and Deselect events of an XMLNodes object.

public delegate void ContextChangeEventHandler(System::Object ^ sender, ContextChangeEventArgs ^ e);
public delegate void ContextChangeEventHandler(object sender, ContextChangeEventArgs e);
type ContextChangeEventHandler = delegate of obj * ContextChangeEventArgs -> unit
Public Delegate Sub ContextChangeEventHandler(sender As Object, e As ContextChangeEventArgs)

Parameters

sender
Object

The source of the event.

e
ContextChangeEventArgs

A ContextChangeEventArgs that contains the event data.

Examples

The following code example demonstrates event handlers for the Microsoft.Office.Tools.Word.XMLNode.Select, Microsoft.Office.Tools.Word.XMLNode.Deselect, Microsoft.Office.Tools.Word.XMLNode.ContextEnter, and Microsoft.Office.Tools.Word.XMLNode.ContextLeave events. When the Microsoft.Office.Tools.Word.XMLNode.Select and Microsoft.Office.Tools.Word.XMLNode.Deselect events are raised, the event handlers add double lines to the borders of the selection or remove the double lines, depending on the event. When the Microsoft.Office.Tools.Word.XMLNode.ContextEnter and Microsoft.Office.Tools.Word.XMLNode.ContextLeave events are raised, the event handlers display messages that state the names of the newly selected node and the previously selected node. This example assumes that the current document contains an XMLNode named CustomerNode.

private void XMLNodeSelections()
{
    this.CustomerNode.ContextEnter +=
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        CustomerNode_ContextEnter);

    this.CustomerNode.ContextLeave +=
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        CustomerNode_ContextLeave);

    this.CustomerNode.Select += 
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        CustomerNode_Select); 

    this.CustomerNode.Deselect +=
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        CustomerNode_Deselect);
}

void CustomerNode_Select(object sender, 
    Microsoft.Office.Tools.Word.ContextChangeEventArgs e)
{
    e.Selection.Borders.OutsideLineStyle =
        Word.WdLineStyle.wdLineStyleDouble;
}

void CustomerNode_Deselect(object sender,
    Microsoft.Office.Tools.Word.ContextChangeEventArgs e)
{
    e.Selection.Borders.OutsideLineStyle =
        Word.WdLineStyle.wdLineStyleNone;
}

void CustomerNode_ContextEnter(object sender,
    Microsoft.Office.Tools.Word.ContextChangeEventArgs e)
{
    MessageBox.Show("You entered the node '" +
        e.NewXMLNode.BaseName + "'.");
}

void CustomerNode_ContextLeave(object sender,
    Microsoft.Office.Tools.Word.ContextChangeEventArgs e)
{
    MessageBox.Show("You left the node '" +
        e.OldXMLNode.BaseName + "'.");
}
Private Sub CustomerNode_Select(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs) _
    Handles CustomerNode.Select

    e.Selection.Borders.OutsideLineStyle = _
        Word.WdLineStyle.wdLineStyleDouble
End Sub

Private Sub CustomerNode_Deselect(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs) _
    Handles CustomerNode.Deselect

    e.Selection.Borders.OutsideLineStyle = _
        Word.WdLineStyle.wdLineStyleNone
End Sub

Private Sub CustomerNode_ContextEnter(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs) _
    Handles CustomerNode.ContextEnter

    MsgBox("You entered the node '" & e.NewXMLNode.BaseName & "'.")
End Sub

Private Sub CustomerNode_ContextLeave(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs) _
    Handles CustomerNode.ContextLeave

    MsgBox("You left the node '" & e.OldXMLNode.BaseName & "'.")
End Sub

Remarks

When you create a ContextChangeEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, until you remove the delegate.

Applies to