Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-change-the-spacing-and-alignment-of-toolstrip-items-in-windows-forms.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

3.8 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Change the Spacing and Alignment of ToolStrip Items 03/30/2017
csharp
vb
ToolStrip control [Windows Forms], aligning items
examples [Windows Forms], toolbars
toolbars [Windows Forms], aligning items
cd483466-0f49-43df-addf-e2b5fcd64027

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

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

Because the default value of the xref:System.Windows.Forms.ToolStripItem.AutoSize%2A property is true, controls are sized automatically unless you set the xref:System.Windows.Forms.ToolStripItem.AutoSize%2A property to false.

To manually size a ToolStripItem

  1. Set the xref:System.Windows.Forms.ToolStripItem.AutoSize%2A property to false for the associated control.

    ToolStripButton1.AutoSize = False  
    
    toolStripButton1.AutoSize = false;  
    
  2. Set the xref:System.Windows.Forms.ToolStripItem.Size%2A property the way you want for the associated xref:System.Windows.Forms.ToolStripItem.

To set the spacing of a ToolStripItem

  1. Insert the desired values, in pixels, into the xref:System.Windows.Forms.ToolStripItem.Margin%2A property of the associated control.

    The values of the xref:System.Windows.Forms.ToolStripItem.Margin%2A 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

  1. Set the xref:System.Windows.Forms.ToolStripItem.Alignment%2A property to xref:System.Windows.Forms.ToolStripItemAlignment.Right for the associated control. By default, xref:System.Windows.Forms.ToolStripItem.Alignment%2A is set to xref:System.Windows.Forms.ToolStripItemAlignment.Left, which aligns controls to the left side of the xref:System.Windows.Forms.ToolStrip.

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

To arrange ToolStrip items on the ToolStrip

See also