C# comboBox without dropDown [closed]

橙三吉。 提交于 2019-12-13 11:02:37

问题


I have ordinary combobox and I want to prevent any changes on it, so I want to make it not show dropdown. Is it possible?

I've tried changing dropDownStyle to simple, but then it shows list of items below.


回答1:


One way to achieve this is to create readonly TextBox over the combo, wirh exact size and font of the combo, so the user possibly will not notice any difference.




回答2:


if you don't want to allow user to do anything with combobox you can use this code in the constructor

public Form1()
{
    InitializeComponent();
    comboBox1.Enabled = false;  
}

else if you want to prevent user from writing anything in the combobox to select the items in combobox you can use this code

{
    InitializeComponent();
    comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; 
}



回答3:


If you don't want to allow any changes on the control than I think you should set its Enabled property to false http://msdn.microsoft.com/en-us/library/system.windows.forms.control.enabled.aspx



来源:https://stackoverflow.com/questions/10567331/c-sharp-combobox-without-dropdown

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!