ContextChangeEventHandler 委派

表示將會處理 XMLNode 物件之 SelectDeselectContextEnterContextLeave 事件以及 XMLNodes 物件之 ContextEnterContextLeaveSelectDeselect 事件的方法。

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

語法

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

參數

備註

在建立 ContextChangeEventHandler 委派 (Delegate) 時,您要識別處理事件的方法。 若要讓此事件與您的事件處理常式產生關聯,請將委派的執行個體加入至此事件。 在您移除該委派之前,每當事件發生,就會呼叫事件處理常式。

範例

下列程式碼範例會示範 XMLNode.SelectXMLNode.DeselectXMLNode.ContextEnterXMLNode.ContextLeave 事件的事件處理常式。 當引發 XMLNode.SelectXMLNode.Deselect 事件時,事件處理常式會為選取範圍的邊框加上雙線,或是移除雙線 (視事件而定)。 當引發 XMLNode.ContextEnterXMLNode.ContextLeave 事件時,事件處理常式會顯示訊息,說明最新選取的節點以及上一個所選節點的名稱。 此範例假設目前的文件包含名為 CustomerNode 的 XMLNode

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

請參閱

參考

Microsoft.Office.Tools.Word 命名空間