Using the Actions Pane Object

VSTO provides an ActionsPane object that enables you to customize the task pane with one line of code. You can think of the actions pane as a container for Windows Forms controls. The actions pane sits inside the Document Actions task pane, which is hosted within the Word or Excel task pane. To customize the Document Actions task pane, you simply add controls to the ActionsPane object.

You can add a Windows Forms control directly to the actions pane through code. As soon as you add the control, the Document Actions task pane becomes visible in the application and displays your control. For example, if you want to display a DateTimePicker control on the actions pane, you can write the code in Listing 5.2. This code displays the DateTimePicker control on the task pane as soon as the document opens because the code is written in the Startup event handler of the document.

Listing 5.2. Adding a control to the actions pane in Word

Private Sub ThisDocument_Startup(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Startup

Me.ActionsPane.Controls.Add(New DateTimePicker)

End Sub

If you want to display controls on the actions pane in response to events, you can write code against any event in Word or Excel. For example, you can capture the SelectionChange event of a worksheet and make changes to controls on the actions pane, as you will see later in the "Designing Actions Pane Solutions" section. You can also choose to map XML to your document and show and hide controls on the actions pane according to the user's cursor location, as you will see later in "Creating Context-Sensitive Solutions."

0 0

Post a comment