Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/stretch-a-toolstriptextbox-to-fill-the-remaining-width-of-a-toolstrip-wf.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

2.4 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Stretch a ToolStripTextBox to Fill the Remaining Width of a ToolStrip 03/30/2017
csharp
vb
text boxes [Windows Forms], stretching in ToolStrip control [Windows Forms]
ToolStrip control [Windows Forms], stretching a text box
0e610fbf-85fe-414c-900c-9704a5dd5cc6

How to: Stretch a ToolStripTextBox to Fill the Remaining Width of a ToolStrip (Windows Forms)

When you set the xref:System.Windows.Forms.ToolStrip.Stretch%2A property of a xref:System.Windows.Forms.ToolStrip control to true, the control fills its container from end to end, and resizes when its container resizes. In this configuration, you may find it useful to stretch an item in the control, such as a xref:System.Windows.Forms.ToolStripTextBox, to fill the available space and to resize when the control resizes. This stretching is useful, for example, if you want to achieve appearance and behavior similar to the address bar in Microsoft® Internet Explorer.

Example

The following code example provides a class derived from xref:System.Windows.Forms.ToolStripTextBox called ToolStripSpringTextBox. This class overrides the xref:System.Windows.Forms.ToolStripTextBox.GetPreferredSize%2A method to calculate the available width of the parent xref:System.Windows.Forms.ToolStrip control after the combined width of all other items has been subtracted. This code example also provides a xref:System.Windows.Forms.Form class and a Program class to demonstrate the new behavior.

[!code-csharpToolStripSpringTextBox#00] [!code-vbToolStripSpringTextBox#00]

Compiling the Code

This example requires:

  • References to the System, System.Drawing, and System.Windows.Forms assemblies.

See also