Share via


How to: Change the Spacing and Alignment of ToolStrip Items in Windows Forms

The ToolStrip control fully supports layout features such as sizing, the spacing of ToolStripItem controls relative to each other, the arrangement of controls on the ToolStrip, and the spacing of controls relative to the ToolStrip.

Because the default value of the AutoSize property is true, controls are sized automatically unless you set the AutoSize property to false.

To manually size a ToolStripItem

  1. Set the AutoSize property to false for the associated control.

    ToolStripButton1.AutoSize = False
    
    toolStripButton1.AutoSize = false;
    
  2. Set the Size property the way you want for the associated ToolStripItem.

To set the spacing of a ToolStripItem

  • Insert the desired values, in pixels, into the Margin property of the associated control.

    The values of the Margin property specify the spacing between the item and adjacent items in this order: Left, Top, Right, and Bottom.

    ToolStripTextBox1.Margin = New System.Windows.Forms.Padding _
        (3, 0, 3, 0)
    
    toolStripTextBox1.Margin = new System.Windows.Forms.Padding 
        (3, 0, 3, 0);
    

To align a ToolStripItem to the right side of the ToolStrip

  • Set the Alignment property to Right for the associated control. By default, Alignment is set to Left, which aligns controls to the left side of the ToolStrip.

    ToolStripSplitButton1.Alignment = _
        System.Windows.Forms.ToolStripItemAlignment.Right
    
    toolStripSplitButton1.Alignment = 
        System.Windows.Forms.ToolStripItemAlignment.Right;
    

To arrange ToolStrip items on the ToolStrip

  • Set the LayoutStyle property to the value of ToolStripLayoutStyle that you want.

    ToolStripDropDown1.LayoutStyle = _
        System.Windows.Forms.ToolStripLayoutStyle.Flow
    
    toolStripDropDown1.LayoutStyle = 
        System.Windows.Forms.ToolStripLayoutStyle.Flow;
    

See Also

Concepts

ToolStrip Control Architecture

ToolStrip Technology Summary

Reference

ToolStrip Control Overview (Windows Forms)

ToolStrip

Layout

LayoutCompleted

LayoutSettings

TextImageRelation

Placement

CanOverflow