ContextChangeEventHandler 委托
表示将处理 XMLNode 对象的 Select、Deselect、ContextEnter 和 ContextLeave 事件以及 XMLNodes 对象的 ContextEnter、ContextLeave、Select 和 Deselect 事件的方法。
命名空间: 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
)
参数
- sender
类型:System.Object
事件源。
备注
当创建 ContextChangeEventHandler 委托时,将标识处理事件的方法。 若要使该事件与事件处理程序相关联,请将该委托的一个实例添加到事件中。 每当事件出现时就调用事件处理程序,直到移除该委托。
示例
下面的代码示例演示 XMLNode.Select、XMLNode.Deselect、XMLNode.ContextEnter 和 XMLNode.ContextLeave 事件的事件处理程序。 引发 XMLNode.Select 和 XMLNode.Deselect 事件时,事件处理程序会根据具体事件为所选内容的边框添加双线或移除双线。 引发 XMLNode.ContextEnter 和 XMLNode.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 + "'.");
}