ContextChangeEventHandler 委托

表示将处理 XMLNode 对象的 SelectDeselectContextEnterContextLeave 事件以及 XMLNodes 对象的 ContextEnterContextLeaveSelectDeselect 事件的方法。

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

语法

声明
Public Delegate Sub ContextChangeEventHandler ( _
    sender As Object, _
    e As ContextChangeEventArgs _
)
public delegate void ContextChangeEventHandler(
    Object sender,
    ContextChangeEventArgs e
)

参数

备注

当创建 ContextChangeEventHandler 委托时,将标识处理事件的方法。 若要使该事件与事件处理程序相关联,请将该委托的一个实例添加到事件中。 每当事件出现时就调用事件处理程序,直到移除该委托。 有关委托的更多信息,请参见事件和委托

示例

下面的代码示例演示 XMLNode.SelectXMLNode.DeselectXMLNode.ContextEnterXMLNode.ContextLeave 事件的事件处理程序。 引发 XMLNode.SelectXMLNode.Deselect 事件时,事件处理程序会根据具体事件为所选内容的边框添加双线或移除双线。 引发 XMLNode.ContextEnterXMLNode.ContextLeave 事件时,事件处理程序会显示消息,指出最新选择的节点和之前选择的节点的名称。 此示例假定当前文档包含一个名为 CustomerNode 的 XMLNode

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

请参见

参考

Microsoft.Office.Tools.Word 命名空间