Evento XMLNodes.AfterInsert

Ocorre quando o usuário adicionar novo Microsoft.Office.Interop.Word.XMLNode à coleção ou em um de seus descendentes.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (em Microsoft.Office.Tools.Word.dll)

Sintaxe

'Declaração
Event AfterInsert As NodeInsertAndDeleteEventHandler
event NodeInsertAndDeleteEventHandler AfterInsert

Exemplos

O exemplo de código a seguir demonstra manipuladores de eventos para os eventos de AfterInsert e de BeforeDelete .O código exibe uma caixa de mensagem antes que Microsoft.Office.Interop.Word.XMLNode seja excluído do documento e depois Microsoft.Office.Interop.Word.XMLNode é adicionado ao documento.O exemplo também usa o método de Add para adicionar um novo elemento a uma coleção de XMLNodes em um intervalo especificado e disparar o evento por meio de AfterInsert .Este exemplo assume que o documento atual contém uma coleção de XMLNodes chamada SampleInsertNodes, que tem XMLNode pai chamado SampleNode.

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.");
    }
}

Segurança do .NET Framework

Consulte também

Referência

XMLNodes Interface

Namespace Microsoft.Office.Tools.Word