用户也可以输入自己的值的组合框或下拉框?
您是否可以有一个组合框或下拉框,用户可以从给定选项列表中进行选择,或输入自己的值?
Can you have a combo or drop-down box where the user can either choose from a list of given alternatives, or enter their own value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是标准
ComboBox
控件的一项功能。其精确行为取决于您为控件的Style
属性设置的值。以下是选项的快速概述:vbComboDropDown
是默认样式。该组合框看起来像带有下拉箭头的单行文本框。用户可以在文本框中键入任意文本,也可以从下拉列表中选择预定义选项之一。vbComboSimple
为您提供旧的经典风格组合框。这实际上只是一个融合在列表框顶部的文本框(这就是组合框控件的名字的由来!)。与默认样式一样,用户可以在顶部的文本框中键入任意文本,也可以从下面的列表框中选择预定义的选项之一。此样式与默认样式之间的唯一真正区别是所有可用选项始终在屏幕上可见。它占用了更多的屏幕空间,但它使用户更容易准确地看到他们的选择。
vbComboDropDownList
将生成一个看起来非常类似于第一个(默认)样式的组合框,只不过用户无法能够在文本中键入任意文本盒子。他们只能选择下拉列表中可用的预定义选项之一。作为我尽力描述的补充,您还可以查看 Microsoft 的Win32 组合框控件的文档,附有屏幕截图。 VB 6 控件只是标准 Win32 控件的包装,因此您看到的所有内容对于 VB 6 应用程序来说都是相同的。唯一的区别是样式的名称 - 您可以使用
vb*
常量之一,而不是设置CBS_*
标志之一。在这种情况下,听起来您想要第一个选项,
vbComboDropDown
。Yes, this is a feature of the standard
ComboBox
control. Its precise behavior depends on the value you set for the control'sStyle
property. Here's a quick run-down of the options:vbComboDropDown
is the default style. The combo box looks like a single-line text box with a drop-down arrow. The user can either type arbitrary text into the text box, or they can select one of the pre-defined options from the drop-down list.vbComboSimple
gets you the old classic-style combo box. This is literally just a text box fused on top of a list box (and that's how the combo box control got its name!). Like the default style, the user can either type arbitrary text into the text box at the top, or they can select one of the pre-defined options from the list box underneath.The only real difference between this style and the default style is that all of the available options are always visible on the screen. It takes up more screen real estate, but it makes it easier for the user to see exactly what their choices are.
vbComboDropDownList
will produce a combo box that looks very much like the first (default) style, except that the user will not be able to type arbitrary text into the text box. They can only choose one of the pre-defined options available in the drop-down list.As a supplement to my best-effort descriptions, you can also see Microsoft's documentation for the Win32 Combo Box control, complete with screenshots. The VB 6 control is just a wrapper around the standard Win32 control, so everything you see there will be the same for a VB 6 application. The only difference is the names of the styles—instead of setting one of the
CBS_*
flags, you use one of thevb*
constants.In this case, it sounds like you want the first option,
vbComboDropDown
.这通常被简单地称为组合框,您必须指定您正在使用的小部件工具包,在 Cocoa 中这是一个 NSCombobox,在 java.swing 中它只是一个 swing.combobox,在 QT 中是 Qcombobox。
That is usally called quite simply a combobox, you will have to specify what widget toolkit you are using though, in Cocoa this is an NSCombobox, in java.swing it's just a swing.combobox, in QT a Qcombobox.