ContextChangeEventArgs 接口

XMLNode 对象的 SelectDeselectContextEnterContextLeave 事件以及 XMLNodes 对象的 ContextEnterContextLeaveSelectDeselect 事件提供数据。

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

语法

声明
<GuidAttribute("7403c9da-5555-41ed-8288-bf92e780d660")> _
Public Interface ContextChangeEventArgs
[GuidAttribute("7403c9da-5555-41ed-8288-bf92e780d660")]
public interface ContextChangeEventArgs

ContextChangeEventArgs 类型公开以下成员。

属性

  名称 说明
公共属性 NewXMLNode 获取选择已移动到的 XMLNode 控件。
公共属性 OldXMLNode 获取选择已从其移开的 XMLNode 控件。
公共属性 Reason 获取选择更改的原因。
公共属性 Selection 获取选择的文本,包括 XML 元素。

页首

示例

下面的代码示例演示 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 命名空间