共用方式為


NodeInsertAndDeleteEventArgs 介面

提供 XMLNode 控制項的 AfterInsertBeforeDelete 事件的資料,以及 XMLNodes 控制項的 AfterInsertBeforeDelete 事件的資料。

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

語法

'宣告
<GuidAttribute("c878142e-6a71-4bf4-82fc-ba9122596104")> _
Public Interface NodeInsertAndDeleteEventArgs
[GuidAttribute("c878142e-6a71-4bf4-82fc-ba9122596104")]
public interface NodeInsertAndDeleteEventArgs

NodeInsertAndDeleteEventArgs 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 InUndoRedo 取得值,指出動作是否為復原或取消命令的結果。

回頁首

範例

下列程式碼範例會示範 AfterInsertBeforeDelete 事件的事件處理常式。 這些事件處理常式在刪除文件中的 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.");
    }
}

請參閱

參考

Microsoft.Office.Tools.Word 命名空間