NodeInsertAndDeleteEventHandler 委托
表示处理 XMLNode 控件的 AfterInsert 和 BeforeDelete 事件,以及 XMLNodes 控件的 AfterInsert 和 BeforeDelete 事件的方法。
命名空间: Microsoft.Office.Tools.Word
程序集: Microsoft.Office.Tools.Word(在 Microsoft.Office.Tools.Word.dll 中)
语法
声明
Public Delegate Sub NodeInsertAndDeleteEventHandler ( _
sender As Object, _
e As NodeInsertAndDeleteEventArgs _
)
public delegate void NodeInsertAndDeleteEventHandler(
Object sender,
NodeInsertAndDeleteEventArgs e
)
参数
- sender
类型:System.Object
事件源。
备注
当创建 NodeInsertAndDeleteEventHandler 委托时,将标识处理事件的方法。若要使该事件与事件处理程序相关联,请将该委托的一个实例添加到事件中。每当事件出现时就调用事件处理程序,直到移除该委托。有关委托的更多信息,请参见事件和委托。
示例
下面的代码示例演示 AfterInsert 和 BeforeDelete 事件的事件处理程序。这些事件处理程序在从该文档删除 XMLNode 之前,将 XMLNode 添加到该文档之后,显示一个消息框。此示例还使用 RemoveChild 方法删除节点,并以编程方式引发 BeforeDelete 事件。此示例假定当前文档包含一个名为 CustomerNode 的 XMLNode,它包含一个名为 CustomerDateNode 的子节点。
Private Sub XMLNodeInsertAndDelete()
Me.CustomerNode.RemoveChild(Me.CustomerDateNode.InnerObject)
End Sub
Private Sub XMLNode_BeforeDelete(ByVal sender As Object, _
ByVal e As Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs) _
Handles CustomerDateNode.BeforeDelete
Dim tempNode As Microsoft.Office.Tools.Word.XMLNode = _
CType(sender, Microsoft.Office.Tools.Word.XMLNode)
If e.InUndoRedo Then
MsgBox(tempNode.BaseName & " element is about to be " & _
"deleted as a result of an undo or redo operation.")
Else
MsgBox(tempNode.BaseName & " element is about to be " & _
"deleted.")
End If
End Sub
Private Sub XMLNode_AfterInsert(ByVal sender As Object, _
ByVal e As Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs) _
Handles CustomerDateNode.AfterInsert
Dim tempNode As Microsoft.Office.Tools.Word.XMLNode = _
CType(sender, Microsoft.Office.Tools.Word.XMLNode)
If e.InUndoRedo Then
MsgBox(tempNode.BaseName & " element was " & _
"inserted as a result of an undo or redo operation.")
Else
MsgBox(tempNode.BaseName & " element was inserted.")
End If
End Sub
private void XMLNodeInsertAndDelete()
{
this.CustomerDateNode.AfterInsert +=
new Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventHandler(
XMLNode_AfterInsert);
this.CustomerDateNode.BeforeDelete +=
new Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventHandler(
XMLNode_BeforeDelete);
this.CustomerNode.RemoveChild(this.CustomerDateNode.InnerObject);
}
void XMLNode_BeforeDelete(object sender,
Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs e)
{
Microsoft.Office.Tools.Word.XMLNode tempNode =
(Microsoft.Office.Tools.Word.XMLNode)sender;
if (e.InUndoRedo)
{
MessageBox.Show(tempNode.BaseName + " element is about to be " +
"deleted as a result of an undo or redo operation.");
}
else
{
MessageBox.Show(tempNode.BaseName + " element is about to be " +
"deleted.");
}
}
void XMLNode_AfterInsert(object sender,
Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs e)
{
Microsoft.Office.Tools.Word.XMLNode tempNode =
(Microsoft.Office.Tools.Word.XMLNode)sender;
if (e.InUndoRedo)
{
MessageBox.Show(tempNode.BaseName + " element was " +
"inserted as a result of an undo or redo operation.");
}
else
{
MessageBox.Show(tempNode.BaseName + " element was inserted.");
}
}