ToolStripComboBox 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示在 . 中正确呈现的一个 ToolStripComboBoxToolStrip。
public ref class ToolStripComboBox : System::Windows::Forms::ToolStripControlHost
[System.Windows.Forms.Design.ToolStripItemDesignerAvailability(System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ContextMenuStrip | System.Windows.Forms.Design.ToolStripItemDesignerAvailability.MenuStrip | System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ToolStrip)]
public class ToolStripComboBox : System.Windows.Forms.ToolStripControlHost
[<System.Windows.Forms.Design.ToolStripItemDesignerAvailability(System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ContextMenuStrip | System.Windows.Forms.Design.ToolStripItemDesignerAvailability.MenuStrip | System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ToolStrip)>]
type ToolStripComboBox = class
inherit ToolStripControlHost
Public Class ToolStripComboBox
Inherits ToolStripControlHost
- 继承
- 继承
-
ToolStripComboBox
- 属性
示例
下面的代码示例演示 ToolStripComboBox 了各种属性设置,包括自动完成。
using System;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public class Form1 : Form
{
private ToolStrip toolStrip1;
private ToolStripComboBox toolStripComboBox1;
public Form1()
{
InitializeComponent();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
private void InitializeComponent()
{
toolStrip1 = new System.Windows.Forms.ToolStrip();
toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox();
toolStrip1.SuspendLayout();
SuspendLayout();
//
// toolStrip1
//
toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
toolStripComboBox1});
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";
// The following code example demonstrates the syntax for setting
// various ToolStripComboBox properties.
//
toolStripComboBox1.AutoCompleteCustomSource.AddRange(new string[] {
"aaa",
"bbb",
"ccc"});
toolStripComboBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
toolStripComboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
toolStripComboBox1.DropDownHeight = 110;
toolStripComboBox1.DropDownWidth = 122;
toolStripComboBox1.FlatStyle = System.Windows.Forms.FlatStyle.Standard;
toolStripComboBox1.IntegralHeight = false;
toolStripComboBox1.Items.AddRange(new object[] {
"xxx",
"yyy",
"zzz"});
toolStripComboBox1.MaxDropDownItems = 9;
toolStripComboBox1.MergeAction = System.Windows.Forms.MergeAction.Insert;
toolStripComboBox1.Name = "toolStripComboBox1";
toolStripComboBox1.Size = new System.Drawing.Size(121, 25);
toolStripComboBox1.Sorted = true;
//
// Form1
//
ClientSize = new System.Drawing.Size(292, 273);
Controls.Add(toolStrip1);
Name = "Form1";
toolStrip1.ResumeLayout(false);
toolStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
}
}
Imports System.Text
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Private toolStrip1 As ToolStrip
Private toolStripComboBox1 As ToolStripComboBox
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()
toolStripComboBox1 = New System.Windows.Forms.ToolStripComboBox()
toolStrip1.SuspendLayout()
SuspendLayout()
'
' toolStrip1
'
toolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {toolStripComboBox1})
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"
' The following code example demonstrates the syntax for setting
' various ToolStripComboBox properties.
'
toolStripComboBox1.AutoCompleteCustomSource.AddRange(New String() {"aaa", "bbb", "ccc"})
toolStripComboBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend
toolStripComboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource
toolStripComboBox1.DropDownHeight = 110
toolStripComboBox1.DropDownWidth = 122
toolStripComboBox1.FlatStyle = System.Windows.Forms.FlatStyle.Standard
toolStripComboBox1.IntegralHeight = False
toolStripComboBox1.Items.AddRange(New Object() {"xxx", "yyy", "zzz"})
toolStripComboBox1.MaxDropDownItems = 9
toolStripComboBox1.MergeAction = System.Windows.Forms.MergeAction.Insert
toolStripComboBox1.Name = "toolStripComboBox1"
toolStripComboBox1.Size = New System.Drawing.Size(121, 25)
toolStripComboBox1.Sorted = True
'
' 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
注解
ToolStripComboBox 是 ComboBox 针对在 a ToolStrip. 中托管的优化。 托管控件的属性和事件的子集在 ToolStripComboBox 级别公开,但基础 ComboBox 控件可通过 ComboBox 该属性完全访问。
显示 ToolStripComboBox 一个编辑字段与一 ListBox个组合在一起,允许用户从列表中选择或输入新文本。 默认情况下,显示 ToolStripComboBox 具有隐藏下拉列表的编辑字段。 该 DropDownStyle 属性确定要显示的组合框的样式。 可以输入一个允许简单下拉列表的值,其中列表始终显示,下拉列表框,其中文本部分不可编辑,必须选择箭头以查看下拉列表框,或默认下拉列表框,其中文本部分可编辑,用户必须按箭头键查看列表。 若要始终显示用户无法编辑的列表,请使用 ListBox 控件。
若要在运行时将对象添加到列表中,请使用该方法分配对象引用 AddRange 数组。 然后,该列表显示每个对象的默认字符串值。 可以使用该方法添加单个对象 Add 。
除了显示和选择功能之外,还提供了 ToolStripComboBox 一项功能,使你能够有效地将项添加到 ToolStripComboBox 列表的项中并查找文本。 使用 BeginUpdate 和 EndUpdate 方法,可以在每次将项添加到列表中时,无需重新绘制控件即可将大量项 ToolStripComboBox 添加到列表中。 使用 FindString 和 FindStringExact 方法可以搜索列表中包含特定搜索字符串的项。
使用 SelectedIndex 属性获取或设置下拉列表中的当前项,并使用 SelectedItem 该属性获取或设置对下拉列表中当前项的引用。
构造函数
| 名称 | 说明 |
|---|---|
| ToolStripComboBox() |
初始化 ToolStripComboBox 类的新实例。 |
| ToolStripComboBox(Control) |
初始化派生自基控件的 ToolStripComboBox 类的新实例。 |
| ToolStripComboBox(String) |
使用指定名称初始化类的新实例 ToolStripComboBox 。 |
属性
方法
活动
显式接口实现
| 名称 | 说明 |
|---|---|
| IDropTarget.OnDragDrop(DragEventArgs) |
引发 DragDrop 事件。 (继承自 ToolStripItem) |
| IDropTarget.OnDragEnter(DragEventArgs) |
引发 DragEnter 事件。 (继承自 ToolStripItem) |
| IDropTarget.OnDragLeave(EventArgs) |
引发 DragLeave 事件。 (继承自 ToolStripItem) |
| IDropTarget.OnDragOver(DragEventArgs) |
引发 |