Delegat ContextChangeEventHandler

Represents the method that will handle the Select, Deselect, ContextEnter and ContextLeave events of an XMLNode object and the ContextEnter, ContextLeave, Select, and Deselect events of an XMLNodes object.

Przestrzeń nazw:  Microsoft.Office.Tools.Word
Zestaw:  Microsoft.Office.Tools.Word (w Microsoft.Office.Tools.Word.dll)

Składnia

'Deklaracja
Public Delegate Sub ContextChangeEventHandler ( _
    sender As Object, _
    e As ContextChangeEventArgs _
)
public delegate void ContextChangeEventHandler(
    Object sender,
    ContextChangeEventArgs e
)

Parametry

Uwagi

Podczas tworzenia ContextChangeEventHandler pełnomocnika, należy określić metodę, która będzie obsługiwać zdarzenie.Aby skojarzyć zdarzenie z obsługi zdarzenia, należy dodać wystąpienie pełnomocnika do zdarzenia.Program obsługi zdarzeń jest nazywany w każdym przypadku, gdy wystąpi zdarzenie, dopóki nie usuniesz pełnomocnika.

Przykłady

Poniższy przykład kodu demonstruje obsługę zdarzeń dla zdarzeń XMLNode.Select, XMLNode.Deselect, XMLNode.ContextEnter i XMLNode.ContextLeave.Gdy zdarzenia XMLNode.Select i XMLNode.Deselect są wywoływane, obsługa zdarzeń dodaje podwójne linie do obramowania zaznaczenia lub usuwa podwójne linie, w zależności od zdarzenia.Gdy zdarzenia XMLNode.ContextEnter i XMLNode.ContextLeave są wywoływane, obsługa zdarzeń wyświetla komunikaty, które podają nazwy nowo wybranych węzłów oraz uprzednio wybrany węzeł.W tym przykładzie założono, że bieżący dokument zawiera XMLNode o nazwie CustomerNode.

Private Sub CustomerNode_Select(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs) _
    Handles CustomerNode.Select

    e.Selection.Borders.OutsideLineStyle = _
        Word.WdLineStyle.wdLineStyleDouble
End Sub

Private Sub CustomerNode_Deselect(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs) _
    Handles CustomerNode.Deselect

    e.Selection.Borders.OutsideLineStyle = _
        Word.WdLineStyle.wdLineStyleNone
End Sub

Private Sub CustomerNode_ContextEnter(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs) _
    Handles CustomerNode.ContextEnter

    MsgBox("You entered the node '" & e.NewXMLNode.BaseName & "'.")
End Sub

Private Sub CustomerNode_ContextLeave(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs) _
    Handles CustomerNode.ContextLeave

    MsgBox("You left the node '" & e.OldXMLNode.BaseName & "'.")
End Sub
private void XMLNodeSelections()
{
    this.CustomerNode.ContextEnter +=
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        CustomerNode_ContextEnter);

    this.CustomerNode.ContextLeave +=
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        CustomerNode_ContextLeave);

    this.CustomerNode.Select += 
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        CustomerNode_Select); 

    this.CustomerNode.Deselect +=
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        CustomerNode_Deselect);
}

void CustomerNode_Select(object sender, 
    Microsoft.Office.Tools.Word.ContextChangeEventArgs e)
{
    e.Selection.Borders.OutsideLineStyle =
        Word.WdLineStyle.wdLineStyleDouble;
}

void CustomerNode_Deselect(object sender,
    Microsoft.Office.Tools.Word.ContextChangeEventArgs e)
{
    e.Selection.Borders.OutsideLineStyle =
        Word.WdLineStyle.wdLineStyleNone;
}

void CustomerNode_ContextEnter(object sender,
    Microsoft.Office.Tools.Word.ContextChangeEventArgs e)
{
    MessageBox.Show("You entered the node '" +
        e.NewXMLNode.BaseName + "'.");
}

void CustomerNode_ContextLeave(object sender,
    Microsoft.Office.Tools.Word.ContextChangeEventArgs e)
{
    MessageBox.Show("You left the node '" +
        e.OldXMLNode.BaseName + "'.");
}

Zobacz też

Informacje

Przestrzeń nazw Microsoft.Office.Tools.Word