ContextChangeEventArgs 介面

提供 XMLNode 物件的 SelectDeselectContextEnterContextLeave 事件資料,以及 XMLNodes 物件的 ContextEnterContextLeaveSelectDeselect 事件資料。

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

語法

'宣告
<GuidAttribute("7403c9da-5555-41ed-8288-bf92e780d660")> _
Public Interface ContextChangeEventArgs
[GuidAttribute("7403c9da-5555-41ed-8288-bf92e780d660")]
public interface ContextChangeEventArgs

ContextChangeEventArgs 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 NewXMLNode 取得選取範圍已經移動的 XMLNode 控制項。
公用屬性 OldXMLNode 取得從選取範圍已經移動的 XMLNode 控制項。
公用屬性 Reason 取得選取範圍變更的理由。
公用屬性 Selection 取得選取的文字,包含 XML 項目。

回頁首

範例

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