* 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
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 |
|
|
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
-
Set the xref:System.Windows.Forms.ToolStripItem.AutoSize%2A property to
falsefor the associated control.ToolStripButton1.AutoSize = FalsetoolStripButton1.AutoSize = false; -
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
-
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
-
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.RighttoolStripSplitButton1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
To arrange ToolStrip items on the ToolStrip
-
Set the xref:System.Windows.Forms.ToolStrip.LayoutStyle%2A property to the value of xref:System.Windows.Forms.ToolStripLayoutStyle that you want.
ToolStripDropDown1.LayoutStyle = _ System.Windows.Forms.ToolStripLayoutStyle.FlowtoolStripDropDown1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow;
See also
- xref:System.Windows.Forms.ToolStrip
- xref:System.Windows.Forms.Control.Layout
- xref:System.Windows.Forms.ToolStrip.LayoutCompleted
- xref:System.Windows.Forms.ToolStrip.LayoutSettings%2A
- xref:System.Windows.Forms.ToolStripItem.TextImageRelation%2A
- xref:System.Windows.Forms.ToolStripItem.Placement%2A
- xref:System.Windows.Forms.ToolStrip.CanOverflow%2A
- ToolStrip Control Overview
- ToolStrip Control Architecture
- ToolStrip Technology Summary