How to: Manage Control Layout on Actions Panes

An actions pane is docked to the right of a document or worksheet by default; however, it can be docked to the left, top, or bottom. If you are using multiple user controls, you can write code to properly stack the user controls on the actions pane. For more information, see Actions Pane Overview.

Applies to: The information in this topic applies to document-level projects for the following applications: Excel 2007 and Excel 2010; Word 2007 and Word 2010. For more information, see Features Available by Office Application and Project Type.

The stack order of the controls depends on whether the actions pane is docked vertically or horizontally.

Note

If the user resizes the actions pane at run time, you can set the controls to resize with the actions pane. You can use the Anchor property of a Windows Forms control to anchor controls to the actions pane. For more information, see How to: Anchor Controls on Windows Forms.

You can use the sample code in Walkthrough: Changing the Actions Pane According to User Context to create the multiple actions pane controls needed for the following procedure.

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 Working with Settings.

To set the stack order of the actions pane controls

  1. Open a document-level project for Microsoft Office Word that includes an actions pane with multiple user controls or nested actions pane controls. For more information, see How to: Add an Actions Pane to Word Documents.

  2. Right-click ThisDocument.cs or ThisDocument.vb in Solution Explorer and then click View Code.

  3. In the OrientationChanged event handler of the actions pane, check if the orientation of the actions pane is horizontal.

    Private Sub ActionsPane_OrientationChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles ActionsPane.OrientationChanged
    
        If Me.ActionsPane.Orientation = Orientation.Horizontal Then
    
    private void ActionsPane_OrientationChanged(object sender, EventArgs e)
    {
        if (ActionsPane.Orientation == Orientation.Horizontal)
        {
    
  4. If the orientation is horizontal, stack the action pane controls from the left; otherwise, stack them from the top.

            Me.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromLeft
        Else
            Me.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromTop
        End If
    End Sub
    
            this.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromLeft;
        }
        else
        {
            this.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromTop;
        }
    }
    
  5. In C#, you must add an event handler for the ActionsPane to the Startup event handler. For information about creating event handlers, see How to: Create Event Handlers in Office Projects.

    private void ThisDocument_Startup(object sender, System.EventArgs e)
    {
        this.ActionsPane.OrientationChanged += new EventHandler(ActionsPane_OrientationChanged);
    }
    
  6. Run the project and verify that the actions pane controls are stacked left to right when the actions pane is docked at the top of the document, and the controls are stacked from top to bottom when the actions pane is docked at the right side of the document.

Example

Private Sub ActionsPane_OrientationChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles ActionsPane.OrientationChanged

    If Me.ActionsPane.Orientation = Orientation.Horizontal Then

        Me.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromLeft
    Else
        Me.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromTop
    End If
End Sub
private void ThisDocument_Startup(object sender, System.EventArgs e)
{
    this.ActionsPane.OrientationChanged += new EventHandler(ActionsPane_OrientationChanged);
}

private void ActionsPane_OrientationChanged(object sender, EventArgs e)
{
    if (ActionsPane.Orientation == Orientation.Horizontal)
    {
        this.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromLeft;
    }
    else
    {
        this.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromTop;
    }
}

Compiling the Code

This example requires:

  • A Word document-level project with an actions pane that contains multiple user controls or nested actions pane controls.

See Also

Tasks

How to: Add an Actions Pane to Excel Workbooks

How to: Add an Actions Pane to Word Documents

Walkthrough: Inserting Text into a Document from an Actions Pane

Walkthrough: Changing the Actions Pane According to User Context

Other Resources

Actions Pane Overview