Showing and Hiding Controls on the Actions Pane

In this section you will write code in the ContextEnter and ContextLeave event handlers of the XMLNodes that are mapped to your document. The context is the area between the opening XML tag and its closing tag. This context can include child XML nodes.

The code in Listing 5.14 adds ActionsPaneControl1 to the actions pane when the context of the LetterAddressNode is entered, and shows ActionsPaneControl2 when the context of the LetterContentNode is entered. In addition, the control is removed whenever you exit the context of the XMLNode control. Notice that the variables for the actions pane controls are declared outside the procedure.

Listing 5.14. Adding and removing controls on the actions pane

Dim AddressControl As New ActionsPaneControl1 Dim ContentControl As New ActionsPaneControl2

Private Sub LetterAddressNode_ContextEnter(ByVal sender As Object, ByVal e As _

Microsoft.Office.Tools.Word.ContextChangeEventArgs) Handles LetterAddressNode.ContextEnter

Me.ActionsPane.Controls.Add(AddressControl)

End Sub

Private Sub LetterAddressNode_ContextLeave(ByVal sender As Object, ByVal e As _

Microsoft.Office.Tools.Word.ContextChangeEventArgs) Handles LetterAddressNode.ContextLeave

Me.ActionsPane.Controls.Remove(AddressControl)

End Sub

Private Sub LetterContentNode_ContextEnter(ByVal sender As Object, ByVal e As _

Microsoft.Office.Tools.Word.ContextChangeEventArgs) Handles LetterContentNode.ContextEnter

Me.ActionsPane.Controls.Add(ContentControl)

End Sub

Private Sub LetterContentNode_ContextLeave(ByVal sender As Object, ByVal e As _

Microsoft.Office.Tools.Word.ContextChangeEventArgs) Handles LetterContentNode.ContextLeave

Me.ActionsPane.Controls.Remove(ContentControl)

0 0

Post a comment