XMLNodes.ContextEnter 事件

當游標從節點內容以外的區域,放到 XMLNodes 集合的其中一個節點或子代 (Descendant) 節點時發生。

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

語法

'宣告
Event ContextEnter As ContextChangeEventHandler
event ContextChangeEventHandler ContextEnter

備註

ContextEnter 事件和 Select 事件不一樣。 只有當內容變更時會引發 ContextEnter 事件,且可因為相同階層式層級巢狀中的多重 XMLNodes 控制項而引發。 如需詳細資訊,請參閱XMLNodes 控制項

範例

下列程式碼範例會示範 SelectDeselect、ContextEnter 和 ContextLeave 事件的事件處理常式。 當引發 SelectDeselect 事件時,事件處理常式會為選取範圍的邊框加上雙線,或是移除雙線 (視事件而定)。 當引發 ContextEnter 和 ContextLeave 事件時,事件處理常式會顯示訊息,說明最新選取的節點以及上一個所選節點的名稱。 這個範例假設目前文件包含名為 SampleInsertNodes 的 XMLNodes 集合。

Private Sub SampleInsertNodes_Select(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs)


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

Private Sub SampleInsertNodes_Deselect(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs)


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

Private Sub SampleInsertNodes_ContextEnter(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs)


    MessageBox.Show("You entered the node '" & _
        e.NewXMLNode.BaseName + "'.")
End Sub

Private Sub SampleInsertNodes_ContextLeave(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContextChangeEventArgs)


    MessageBox.Show("You left the node '" & _
        e.OldXMLNode.BaseName + "'.")
End Sub
private void XMLNodesSelections()
{
    this.SampleInsertNodes.ContextEnter +=
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        SampleInsertNodes_ContextEnter);

    this.SampleInsertNodes.ContextLeave +=
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        SampleInsertNodes_ContextLeave);

    this.SampleInsertNodes.Select +=
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        SampleInsertNodes_Select);

    this.SampleInsertNodes.Deselect +=
        new Microsoft.Office.Tools.Word.ContextChangeEventHandler(
        SampleInsertNodes_Deselect);
}

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

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

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

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

.NET Framework 安全性

請參閱

參考

XMLNodes 介面

Microsoft.Office.Tools.Word 命名空間