Compartir a través de


DocumentBase.XMLAfterInsert (Evento)

Se produce cuando un usuario agrega un nuevo elemento XML a un documento.Si se agrega más de un elemento al documento al mismo tiempo (por ejemplo, cuando se corta y se pega código XML), se produce el evento por cada elemento que se inserte.

Espacio de nombres:  Microsoft.Office.Tools.Word
Ensamblado:  Microsoft.Office.Tools.Word.v4.0.Utilities (en Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

Sintaxis

'Declaración
Public Event XMLAfterInsert As DocumentEvents2_XMLAfterInsertEventHandler
public event DocumentEvents2_XMLAfterInsertEventHandler XMLAfterInsert

Ejemplos

En el siguiente ejemplo de código se muestran los controladores de eventos para los eventos XMLAfterInsert y XMLBeforeDelete.En el código se muestra un mensaje antes de eliminar XMLNode del documento y después de agregar XMLNode al documento.Para probar este código de ejemplo, utilice el panel de tareas Estructura XML para agregar elementos XML al documento y, a continuación, pruebe las opciones Deshacer Escribir y Repetir Escribir del menú Edición.En este ejemplo se supone que el documento actual se asigna a un esquema XML válido.Para usar este ejemplo, ejecútelo desde la clase ThisDocument en un proyecto de nivel de documento.

Private Sub DocumentXMLBeforeAndAfterInsert()
    AddHandler Me.XMLAfterInsert, AddressOf ThisDocument_XMLAfterInsert
    AddHandler Me.XMLBeforeDelete, AddressOf ThisDocument_XMLBeforeDelete
End Sub 

Private Sub ThisDocument_XMLBeforeDelete(ByVal DeletedRange As Word.Range, ByVal OldXMLNode As Word.XMLNode, ByVal InUndoRedo As Boolean)
    If InUndoRedo Then
        MessageBox.Show(OldXMLNode.BaseName & " element is about to be deleted as a result" _
            & " of an undo or redo operation.")
    Else
        MessageBox.Show(OldXMLNode.BaseName & " element is about to be deleted.")
    End If
End Sub

Private Sub ThisDocument_XMLAfterInsert(ByVal NewXMLNode As Word.XMLNode, ByVal InUndoRedo As Boolean)
    If InUndoRedo Then
        MessageBox.Show(NewXMLNode.BaseName & " element was " & "inserted as a result " _
            & "of an undo or redo operation.")
    Else
        MessageBox.Show(NewXMLNode.BaseName & " element was inserted.")
    End If
End Sub
private void DocumentXMLBeforeAndAfterInsert()
{
    this.XMLAfterInsert +=
        new Word.DocumentEvents2_XMLAfterInsertEventHandler(
        ThisDocument_XMLAfterInsert);

    this.XMLBeforeDelete +=
        new Word.DocumentEvents2_XMLBeforeDeleteEventHandler(
        ThisDocument_XMLBeforeDelete);
}

void ThisDocument_XMLBeforeDelete(Word.Range DeletedRange,
    Word.XMLNode OldXMLNode, bool InUndoRedo)
{
    if (InUndoRedo)
    {
        MessageBox.Show(OldXMLNode.BaseName +
            " element is about to be deleted as a result" +
            " of an undo or redo operation.");
    }
    else
    {
        MessageBox.Show(OldXMLNode.BaseName +
            " element is about to be deleted.");
    }
}

void ThisDocument_XMLAfterInsert(Word.XMLNode NewXMLNode,
    bool InUndoRedo)
{
    if (InUndoRedo)
    {
        MessageBox.Show(NewXMLNode.BaseName + " element was " +
            "inserted as a result of an undo or redo operation.");
    }
    else
    {
        MessageBox.Show(NewXMLNode.BaseName + " element was inserted.");
    }
}

Seguridad de .NET Framework

Vea también

Referencia

DocumentBase Clase

Microsoft.Office.Tools.Word (Espacio de nombres)