如何使ComboBox在.NET中不可编辑? [英] How can I make a ComboBox non-editable in .NET?
问题描述
我想要一个只选择 ComboBox
,它提供了一个项目列表供用户选择。应该在 ComboBox
控件的文本部分禁用打字。
I want to have a "select-only" ComboBox
that provides a list of items for the user to select from. Typing should be disabled in the text portion of the ComboBox
control.
我最初的谷歌搜索复杂,错误的建议来捕获 KeyPress
事件。
My initial googling of this turned up an overly complex, misguided suggestion to capture the KeyPress
event.
推荐答案
ComboBox的文本部分不可编辑,将DropDownStyle属性设置为DropDownList。 ComboBox现在基本上只是为用户选择。你可以在Visual Studio设计器或C#中这样做:
To make the text portion of a ComboBox non-editable, set the DropDownStyle property to "DropDownList". The ComboBox is now essentially select-only for the user. You can do this in the Visual Studio designer, or in C# like this:
stateComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
这篇关于如何使ComboBox在.NET中不可编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!