Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How does the ToolStrip Layout work?

By default the ToolStrip control utilizes a StackWithOverflow layout that supports overflow and item alignment. Stack refers to how the items are laid out within the ToolStrip, each item stacked aside each other at both ends of the ToolStrip.

ToolStripLayoutStyle ToolStrip.LayoutStyle Stack layouts StackWithOverflow

Default for ToolStrip, this ToolStripLayoutStyle automatically alters it's layout based on the orientation property of the ToolStrip to handle drag to dock scenarios.

VerticalStackWithOverflow

Just like StackWithOverflow except always renders as vertical.

HorizontalStackWithOverflow

Just like StackWithOverflow except always renders horizontal.

Features notes with StackLayouts
  • ToolStripItem.Alignment controls which side of the ToolStrip the item is aligned to.
  • ToolStripItem.Overflow controls whether an item can overflow to the ToolStripOverflow dropdown Always, AsNeeded, or Never.
  • When items do not fit within the ToolStrip, an Overflow button is rendered.  Additional items appear in the ToolStripOverflow dropdown. 
  • On the LayoutCompleted event, the ToolStripItem.Placement property can be inspected to see if an item was placed on the Main toolstrip, the Overflow toolstrip, or if it is not currently showing (usually because the item did not fit on Main and it was set to Overflow.Never).
  • A ToolStrip can be "movable" if it is placed in a ToolStripPanel and it's GripStyle is set to Visible.
Non-Stack layouts Flow

Default for ContextMenuStrip/ToolStripDropDownMenu/ToolStripOverflow, very similar to the FlowLayoutPanel.

Features notes with FlowLayouts

  • All of the properties/methods of the FlowLayoutPanel - FlowBreak, WrapContents, FlowDirection, etc - are exposed off the ToolStrip. LayoutSettings object (LayoutSettings must be casted into a FlowLayoutSettings class).
  • The ToolStripItem.Dock and ToolStripItem.Anchor properties can be used in code to align the items within the row.
  • The ToolStripItem.Alignment property is ignored.
  • On the LayoutCompleted event, the ToolStripItem.Placement property can be inspected to see if an item was placed on the Main toolstrip or didn't fit (None).
  • The ToolStrip grip is not rendered, thus a ToolStrip with LayoutStyle = Flow in a ToolStripPanel cannot be moved.
  • The ToolStrip overflow button is not rendered, ToolStripItem.Overflow is ignored.
Table

Default for StatusStrip, very similar to  TableLayoutPanel.

    toolStrip.LayoutStyle = ToolStripLayoutStyle.Table;
    TableLayoutSettings settings = toolStrip.LayoutSettings as TableLayoutSettings;
    settings.RowCount = 12;
     public class System.Windows.Forms.TableLayoutSettings :
          System.Windows.Forms.LayoutSettings
    {
      public int ColumnCount { get; set; }
      public ColumnStyleCollection ColumnStyles { get; }
      public TableLayoutPanelGrowStyle GrowStyle { get; set; }
      public int RowCount { get; set; }
      public RowStyleCollection RowStyles { get; }
    }

Features notes with TableLayout

  • All of the properties/methods of the TableLayoutPanel – RowCount, ColumnCount, RowSpan, ColumnSpan, RowStyles, ColumnStyles - are exposed off the ToolStrip. LayoutSettings object (LayoutSettings must be casted into a TableLayoutSettings class).
  • The ToolStripItem.Dock and ToolStripItem.Anchor properties can be used in code to align the items within the cell.
  • The ToolStripItem.Alignment property is ignored.
  • On the LayoutCompleted event, the ToolStripItem.Placement property can be inspected to see if an item was placed on the Main toolstrip or didn't fit (None).
  • The ToolStrip grip is not rendered, thus a ToolStrip with LayoutStyle = Table in a ToolStripPanel cannot be moved.
  • The ToolStrip overflow button is not rendered, ToolStripItem.Overflow is ignored.

For StatusStrip, all "Spring" columns are set to 100%, all other columns are set to AutoSize in an overridable method called OnSpringTableLayoutCore.



Page view counter