ToolStripTextBox Class

Note: This class is new in the .NET Framework version 2.0.

Represents a text box in a ToolStrip that allows the user to enter text.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

public class ToolStripTextBox : ToolStripControlHost
public class ToolStripTextBox extends ToolStripControlHost
public class ToolStripTextBox extends ToolStripControlHost

The ToolStripTextBox control allows the user to enter text in an application. This control has additional functionality that is not found in the standard Windows text box control, including multiline editing.

Typically, a ToolStripTextBox control is used to display a single line of text or accept it as input. You can use the Multiline to enable multiple lines of text to be displayed or entered. Set the AcceptsTab and AcceptsReturn properties to true to allow greater text manipulation in a multiline ToolStripTextBox control.

You can limit the amount of text entered into a ToolStripTextBox control by setting the MaxLength property to a specific number of characters. Use the CharacterCasing property to allow the user to type only uppercase, only lowercase, or a combination of uppercase and lowercase characters into the ToolStripTextBox control.

To restrict text from being entered in a ToolStripTextBox control, you can create an event handler for the KeyDown event in order to validate each character entered in the control. You can also restrict all entry of data in a ToolStripTextBox control by setting the ReadOnly property to true.

The following code example demonstrates a ToolStripTextBox with various common property settings, including automatic completion options.

using System;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication2
    public class Form1 : Form
        private ToolStrip toolStrip1;
        private ToolStripTextBox toolStripTextBox1;
        public Form1()
        static void Main()
            Application.Run(new Form1());

        private void InitializeComponent()
            toolStrip1 = new System.Windows.Forms.ToolStrip();
            toolStripTextBox1 = new System.Windows.Forms.ToolStripTextBox();
            // toolStrip1
            toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            toolStrip1.Location = new System.Drawing.Point(0, 0);
            toolStrip1.Name = "toolStrip1";
            toolStrip1.Size = new System.Drawing.Size(292, 25);
            toolStrip1.TabIndex = 0;
            toolStrip1.Text = "toolStrip1";
            // This code example demonstrates the syntax for setting
            // various ToolStripTextBox properties.
            toolStripTextBox1.AcceptsReturn = true;
            toolStripTextBox1.AcceptsTab = true;
            toolStripTextBox1.AutoCompleteCustomSource.AddRange(new string[] {
            "This is line one.",
            "Second line.",
            "Another line."});
            toolStripTextBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
            toolStripTextBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
            toolStripTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            toolStripTextBox1.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            toolStripTextBox1.HideSelection = false;
            toolStripTextBox1.MaxLength = 32000;
            toolStripTextBox1.Name = "toolStripTextBox1";
            toolStripTextBox1.ShortcutsEnabled = false;
            toolStripTextBox1.Size = new System.Drawing.Size(100, 25);
            toolStripTextBox1.Text = "STRING1\r\nSTRING2\r\nSTRING3\r\nSTRING4";
            toolStripTextBox1.TextBoxTextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // Form1
            ClientSize = new System.Drawing.Size(292, 273);
            Name = "Form1";


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0