将禁用组合的背景颜色设置为白色
你好 我有一个可以在运行时启用和禁用的组合框。现在我需要使背景颜色保持不变,即使它被启用或禁用。任何人都可以帮助我吗?
hi
I have a combo box which can enabled and disabled at run time.now i needed to make make the back color constant even if it is enabled or disabled.any one can help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我找到了以下解决方案。
解决方案 1:
在禁用时将下拉样式设置为
"DropDownList"
,然后在启用控件时将其重置为"DropDown"
解决方案 2:
转到此处 http://www.codeproject.com/Articles/ 22454/ReadOnly-ComboBox
第一个解决方案对我有用,第二个解决方案你可以尝试一下。
I found following solutions.
Solution 1:
set the dropdownstyle to be
"DropDownList"
when disabled and then reset it to"DropDown"
when you enabled the controlSolution 2:
Go here http://www.codeproject.com/Articles/22454/ReadOnly-ComboBox
First solution work for me and 2nd solution u can try it.
这对我有用
现在在每个处理程序中只需设置 e.Handled = true
现在,当您必须将其用作启用时,只需删除处理程序并设置
DropDownHeight
This worked for me
Now in each of this handlers just set e.Handled = true
Now when you have to function it as a Enabled just remove the handlers and set the
DropDownHeight
如果这是 WinForms,则将 BackColor 属性设置为您想要的任何值。
如下所述,这不起作用。
If this is WinForms then set the BackColor Property to whatever you want it to be.
As stated below this does NOT work.
根据您的具体需求,谷歌搜索 为我找到了一个潜在的解决方案:
如果您想要使组合框处于禁用状态(不可更改,但看起来与启用时相同),则快速将 Enabled 属性从 true 设置为 false,然后再次按回车键即可实现它,尽管方式有点hacky:
Depending on exactly what you are after, Googling has found me a potential solution:
If what you're after is to get the combobox in a disabled state (unchangable, but looking the same as when enabled), then quickly setting the Enabled property from true, to false, then back again on Enter achieves it, although in a somewhat hacky manner: