How to: Add an Actions Pane to Word Documents
Applies to |
---|
The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office. Project type
Microsoft Office version
For more information, see Features Available by Application and Project Type. |
The Add New Item dialog box contains an actions pane control that is a user control for the actions pane; you can use an actions pane control or a user control with equal results.
For information about how to add an actions pane to a Microsoft Office Excel workbook, see How to: Add an Actions Pane to Excel Workbooks.
Note
You can create an actions pane only in a document-level customization for Word or Excel. You cannot create an actions pane in an application-level add-in. For more information, see Features Available by Application and Project Type.
Note
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.
Creating the Actions Pane Control
To create an actions pane control and insert text in the document
Open your Word document or template project in Visual Studio.
On the Project menu, click Add New Item.
In the Add New Item dialog box, select Actions Pane Control, name it HelloControl, and click Add.
If the actions pane control is not visible in the designer, double-click HelloControl in the designer.
From the Windows Forms tab of the Toolbox, drag a Button control onto the actions pane control.
Add the following code to the Click event handler of the button.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click Globals.ThisDocument.Paragraphs(1).Range.Text = "Hello world!" End Sub
private void button1_Click(object sender, System.EventArgs e) { Globals.ThisDocument.Paragraphs[1].Range.Text = "Hello World!"; }
In C#, you must add an event handler for the button click. You can place this code in the HelloControl constructor after the call to IntializeComponent.
For information about how to create event handlers, see How to: Create Event Handlers in Visual Studio Tools for Office.
public HelloControl() { InitializeComponent(); this.button1.Click += new EventHandler(this.button1_Click); }
Adding the Actions Pane Control to the Actions Pane
To show the actions pane, add a control to it. The following example adds an actions pane control to the actions pane in Word.
To add an actions pane control to the actions pane
Create a new instance of the actions pane control in the ThisDocument class.
Dim hello As New HelloControl
private HelloControl hello = new HelloControl();
Add the following code to the Startup event handler of ThisDocument.
Me.ActionsPane.Controls.Add(hello)
this.ActionsPane.Controls.Add(hello);
See Also
Tasks
Walkthrough: Inserting Text into a Document from an Actions Pane
How to: Add an Actions Pane to Excel Workbooks
Walkthrough: Changing the Actions Pane According to User Context
How to: Manage Control Layout on Actions Panes