ToolStripTextBox Class
Represents a text box in a ToolStrip that allows the user to enter text.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
'Declaration <ToolStripItemDesignerAvailabilityAttribute(ToolStripItemDesignerAvailability.None Or ToolStripItemDesignerAvailability.ToolStrip Or ToolStripItemDesignerAvailability.MenuStrip Or ToolStripItemDesignerAvailability.ContextMenuStrip)> _ Public Class ToolStripTextBox _ Inherits ToolStripControlHost 'Usage Dim instance As ToolStripTextBox
ToolStripTextBox is the TextBox optimized for hosting in a ToolStrip. A subset of the hosted control's properties and events are exposed at the ToolStripTextBox level, but the underlying TextBox control is fully accessible through the TextBox property.
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.
Imports System Imports System.Text Imports System.Windows.Forms Public Class Form1 Inherits Form Private toolStrip1 As ToolStrip Private toolStripTextBox1 As ToolStripTextBox Public Sub New() InitializeComponent() End Sub <STAThread()> _ Shared Sub Main() Application.EnableVisualStyles() Application.Run(New Form1()) End Sub Private Sub InitializeComponent() toolStrip1 = New System.Windows.Forms.ToolStrip() toolStripTextBox1 = New System.Windows.Forms.ToolStripTextBox() toolStrip1.SuspendLayout() SuspendLayout() ' ' toolStrip1 ' toolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {toolStripTextBox1}) 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" + ControlChars.Cr + ControlChars.Lf + "STRING2" + ControlChars.Cr + ControlChars.Lf + "STRING3" + ControlChars.Cr + ControlChars.Lf + "STRING4" toolStripTextBox1.TextBoxTextAlign = System.Windows.Forms.HorizontalAlignment.Center ' ' Form1 ' ClientSize = New System.Drawing.Size(292, 273) Controls.Add(toolStrip1) Name = "Form1" toolStrip1.ResumeLayout(False) toolStrip1.PerformLayout() ResumeLayout(False) PerformLayout() End Sub End Class
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.ToolStripItem
System.Windows.Forms.ToolStripControlHost
System.Windows.Forms.ToolStripTextBox
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.