XMLNodes.AfterInsert 事件
在用户向集合或其子代之一添加新的 Microsoft.Office.Interop.Word.XMLNode 时发生。
命名空间: Microsoft.Office.Tools.Word
程序集: Microsoft.Office.Tools.Word(在 Microsoft.Office.Tools.Word.dll 中)
语法
声明
Event AfterInsert As NodeInsertAndDeleteEventHandler
event NodeInsertAndDeleteEventHandler AfterInsert
示例
下面的代码示例演示 AfterInsert 和 BeforeDelete 事件的事件处理程序。 此代码在从该文档删除 Microsoft.Office.Interop.Word.XMLNode 之前,将 Microsoft.Office.Interop.Word.XMLNode 添加到该文档之后,显示一个消息框。 此示例还使用 Add 方法将新元素添加到指定范围的 XMLNodes 集合中,并以编程方式引发 AfterInsert 事件。 此示例假定当前文档包含一个名为 SampleInsertNodes 的 XMLNodes 集合,该集合具有一个名为 SampleNode 的父 XMLNode。
Private Sub XMLNodeAddAndDelete()
Dim range1 As Object = Me.SampleInsertNodes(1).Range
' This will raise the AfterInsert event.
Dim node1 As Word.XMLNode = _
Me.SampleInsertNodes.Add("MemoFrom", _
Me.SampleNode.NamespaceURI, range1)
End Sub
Private Sub SampleInsertNodes_AfterInsert(ByVal sender As Object, _
ByVal e As Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs)
If e.InUndoRedo Then
MessageBox.Show("A child element of SampleInsertNodes was " & _
"inserted as a result of an undo or redo operation.")
Else
MessageBox.Show("A child element of SampleInsertNodes " & _
"was inserted.")
End If
End Sub
Private Sub SampleInsertNodes_BeforeDelete(ByVal sender As Object, _
ByVal e As Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs)
If e.InUndoRedo Then
MessageBox.Show("A child element of SampleInsertNodes " & _
"is about to be deleted as a result of an undo or " & _
"redo operation.")
Else
MessageBox.Show("A child element of SampleInsertNodes " & _
"is about to be deleted.")
End If
End Sub
private void XMLNodeAddAndDelete()
{
object range1 = this.SampleInsertNodes[1].Range;
this.SampleInsertNodes.AfterInsert +=
new Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventHandler(
SampleInsertNodes_AfterInsert);
this.SampleInsertNodes.BeforeDelete +=
new Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventHandler(
SampleInsertNodes_BeforeDelete);
// This will raise the AfterInsert event.
Word.XMLNode node1 = this.SampleInsertNodes.Add("MemoFrom",
this.SampleNode.NamespaceURI, ref range1);
}
void SampleInsertNodes_AfterInsert(object sender,
Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs e)
{
if (e.InUndoRedo)
{
MessageBox.Show("A child element of SampleInsertNodes was " +
"inserted as a result of an undo or redo operation.");
}
else
{
MessageBox.Show("A child element of SampleInsertNodes " +
"was inserted.");
}
}
void SampleInsertNodes_BeforeDelete(object sender,
Microsoft.Office.Tools.Word.NodeInsertAndDeleteEventArgs e)
{
if (e.InUndoRedo)
{
MessageBox.Show("A child element of SampleInsertNodes " +
"is about to be deleted as a result of an undo or " +
"redo operation.");
}
else
{
MessageBox.Show("A child element of SampleInsertNodes " +
"is about to be deleted.");
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。