다음을 통해 공유


How to: Manage control layout on actions panes

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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 Excel and Word. 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.

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 Personalize the Visual Studio IDE.

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 or Excel workbooks.

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

            this.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromLeft;
        }
        else
        {
            this.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromTop;
        }
    }
    
            Me.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromLeft
        Else
            Me.ActionsPane.StackOrder = Microsoft.Office.Tools.StackStyle.FromTop
        End If
    End Sub
    
  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 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;
    }
}
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

Compile 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