* 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.9 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| How to: Enable AutoComplete in ToolStrip Controls | 03/30/2017 |
|
|
fd66d085-1af1-45d4-930a-cde944da2e16 |
How to: Enable AutoComplete in ToolStrip Controls in Windows Forms
The following procedure combines a xref:System.Windows.Forms.ToolStripLabel with a xref:System.Windows.Forms.ToolStripComboBox that can be dropped down to show a list of items, such as recently visited Web sites. If the user types a character that matches the first character of one of the items in the list, the item is immediately displayed.
Note
Automatic completion works with
ToolStripcontrols in the same way that it works with traditional controls such as xref:System.Windows.Forms.ComboBox and xref:System.Windows.Forms.TextBox.
To enable AutoComplete in a ToolStrip control
-
Create a xref:System.Windows.Forms.ToolStrip control and add items to it.
ToolStrip1 = New System.Windows.Forms.ToolStrip ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem()_ {ToolStripLabel1, ToolStripComboBox1})toolStrip1 = new System.Windows.Forms.ToolStrip(); toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {toolStripLabel1, toolStripComboBox1}); -
Set the xref:System.Windows.Forms.ToolStripItem.Overflow%2A property of the label and the combo box to xref:System.Windows.Forms.ToolStripItemOverflow.Never so that the list is always available regardless of the form's size.
ToolStripLabel1.Overflow = _ System.Windows.Forms.ToolStripItemOverflow.Never ToolStripComboBox1.Overflow = _ System.Windows.Forms.ToolStripItemOverflow.NevertoolStripLabel1.Overflow = _ System.Windows.Forms.ToolStripItemOverflow.Never toolStripComboBox1.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never -
Add words to the Items collection of the xref:System.Windows.Forms.ToolStripComboBox control.
ToolStripComboBox1.Items.AddRange(New Object() {"First Item", _ "Second Item", "Third Item"})toolStripComboBox1.Items.AddRange(new object[] {"First item", "Second item", "Third item"}); -
Set the xref:System.Windows.Forms.ComboBox.AutoCompleteMode%2A property of the combo box to xref:System.Windows.Forms.AutoCompleteMode.Append.
ToolStripComboBox1.AutoCompleteMode = _ System.Windows.Forms.AutoCompleteMode.AppendtoolStripComboBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Append; -
Set the xref:System.Windows.Forms.ComboBox.AutoCompleteSource%2A property of the combo box to xref:System.Windows.Forms.AutoCompleteSource.ListItems.
ToolStripComboBox1.AutoCompleteSource = _ System.Windows.Forms.AutoCompleteSource.ListItemstoolStripComboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
See also
- xref:System.Windows.Forms.ToolStrip
- xref:System.Windows.Forms.ToolStripLabel
- xref:System.Windows.Forms.ToolStripComboBox
- xref:System.Windows.Forms.ToolStripComboBox.AutoCompleteMode%2A
- xref:System.Windows.Forms.ToolStripComboBox.AutoCompleteSource%2A
- ToolStrip Control Overview
- ToolStrip Control Architecture
- ToolStrip Technology Summary