Share via


Resizing the Actions Pane

I recently responded to a question on the Visual Studio Tools for Office Forum (https://forums.microsoft.com/msdn/ShowPost.aspx?PostID=92651) regarding resizing actions panes and I thought I'd blog about it here as well. If you take a look in the documentation for the Width property of the ActionsPane, you'll see the following:

Do not use. The actions pane cannot be resized programmatically.

This is because the ActionsPane object is hosted within the Document Actions task pane. What the documentation doesn't tell you (and I plan to fix this in an upcoming documentation refresh) is that you can resize the Document Actions task pane itself.

You might have a user control that you want to add that is too wide to fit the current width of the task pane.  The Document Actions task pane does not automatically resize to fit controls that you add to it, and if the control is too wide, it will not be completely visible on the task pane.  The following code shows you how you can use the width of the user control (I add 15 to the width to account for margins) to resize the Document Actions task pane.  Add two user controls to your solution (of different sizes), and then try out the code example below. When you double-click the document, the code will add the first user control to the actions pane and resize the Document Actions task pane to fit the width of the user control. When you right-click the document, the code will remove the first control and add the second user control, resizing the task pane accordingly.

Dim wideControl As New UserControl1
Dim narrowControl As New UserControl2
Dim wideWidth As Integer = wideControl.Width + 15
Dim narrowWidth As Integer = narrowControl.Width + 15

Private Sub ThisDocument_BeforeDoubleClick(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ClickEventArgs) _
    Handles Me.BeforeDoubleClick

    Me.ActionsPane.Controls.Remove(narrowControl)
    Me.ActionsPane.Controls.Add(wideControl)
    Me.CommandBars("Task Pane").Width = wideWidth

End Sub

Private Sub ThisDocument_BeforeRightClick(ByVal sender As Object, _
ByVal e As Microsoft.Office.Tools.Word.ClickEventArgs) _
    Handles Me.BeforeRightClick

    Me.ActionsPane.Controls.Remove(wideControl)
    Me.ActionsPane.Controls.Add(narrowControl)
    Me.CommandBars("Task Pane").Width = narrowWidth

End Sub

-- Kathleen McGrath

-----
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at https://www.microsoft.com/info/cpyright.htm.