共用方式為


XMLNodes.BeforeDelete 事件

當使用者在刪除控制項之前,先從集合中刪除 Microsoft.Office.Interop.Word.XMLNode 或從屬節點便會發生。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word (在 Microsoft.Office.Tools.Word.dll 中)

語法

'宣告
Event BeforeDelete As NodeInsertAndDeleteEventHandler
event NodeInsertAndDeleteEventHandler BeforeDelete

備註

如果 InUndoRedo 參數是 true,就不應該變更文件中的 XML。

範例

下列程式碼範例會示範 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 安全性

請參閱

參考

XMLNodes 介面

Microsoft.Office.Tools.Word 命名空間