XMLNode.BeforeDelete 事件 (2007 系統)
更新:2007 年 11 月
當使用者從文件中刪除 XMLNode 控制項,在刪除掉該控制項之前便會發生。
命名空間: Microsoft.Office.Tools.Word
組件: Microsoft.Office.Tools.Word.v9.0 (在 Microsoft.Office.Tools.Word.v9.0.dll 中)
語法
Public Event BeforeDelete As NodeInsertAndDeleteEventHandler
Dim instance As XMLNode
Dim handler As NodeInsertAndDeleteEventHandler
AddHandler instance.BeforeDelete, handler
public event NodeInsertAndDeleteEventHandler BeforeDelete
備註
如果 InUndoRedo 參數為 true,就不該變更文件中的 XML。
範例
下列程式碼範例會示範 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.");
}
}
使用權限
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。