共用方式為


NodeInsertAndDeleteEventHandler 委派

表示方法,這個方法可處理 XMLNode 控制項的 AfterInsertBeforeDelete 事件,以及 XMLNodes 控制項的 AfterInsertBeforeDelete 事件。

命名空間:  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
)

參數

備註

在建立 NodeInsertAndDeleteEventHandler 委派 (Delegate) 時,您要識別處理事件的方法。 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。 在您移除該委派之前,每當事件發生,就會呼叫事件處理常式。 如需委派的詳細資訊,請參閱事件和委派

範例

下列程式碼範例會示範 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 命名空間