Windows窗体控件-启用 [英] windows form control - enable
问题描述
Windows窗体上有两个组合框.
在代码中,取决于按钮的单击事件,它们都会被启用或禁用,即
cbo1.enabled = true; cbo2.enabled = true;
或
cbo1.enabled = false; cbo2.enabled = false;
禁用它们时,cbo2
变灰,但cbo1
不可更改(即已禁用),cbo1
具有白色背景,并且仅其中的文本变灰. cbo1
与cbo2
一样没有完全变灰.
在设计模式下,两个控件的Backcolor
均设置为Window
在设计模式下,两个控件的Forecolor
均设置为WindowText
问题:
您知道为什么cbo1
没有完全变灰吗?
谢谢
检查cbo1是否放置在另一个控件上! /blockquote>
可能发生的情况是,即使看起来像控件的BackColor,它也不再是默认值.
当将颜色更改为某种颜色,然后通过选择默认颜色名称将其更改回原来的颜色时,可能会发生这种情况.这会将以下行放入designer.cs文件中.
此 .cb01.BackColor = System.Drawing.SystemColors.Window;
当控件真正使用其默认颜色设置进行操作时,该行将丢失.
我不知道为什么这会导致问题,但是它具有使启用和禁用的颜色相同的效果.
解决方法:
1)在设计器中显示表格
2)选择cb01
3)转到属性,然后右键单击BackColor
4)如果重置选项可用,则重置
这是重置设计器属性的正确方法,应该可以解决问题.
艾伦.
There are two combo boxes on the windows form.
Inside the code depending on the click event of a button they both become enabled or disabled i.e.
cbo1.enabled = true; cbo2.enabled = true;
or
cbo1.enabled = false; cbo2.enabled = false;
When they are disabled,cbo2
is greyed out but althoughcbo1
is not changeable (i.e. it is disabled)cbo1
has a white background and only the text inside it is greyed out.cbo1
is not completely greyed out as same ascbo2
.
Backcolor
of both controls is set toWindow
in design mode
Forecolor
of both controls is set toWindowText
in design mode
Question:
Do you know why thecbo1
is not completely greyed out?
Thanks解决方案Check whether the cbo1 is placed on another control !!
Pls share your full code to help you!
What may have happened is that the BackColor of the control is no longer the default, even though it looks as if it is.
This can happen when the color is changed to something and then changed back by selecting the default color name. This will have put the following line in the designer.cs file.
this.cb01.BackColor = System.Drawing.SystemColors.Window;
When the control is really operating with it''s default color setting that line will be missing.
I don''t know why this causes a problem but it has the effect of making making the enabled and disabled colors the same.
To fix:
1) Bring up the form in the designer
2) Select cb01
3) Goto properties and right click on the BackColor
4) If the Reset option is available then Reset
This is the proper way to reset a designer property and should fix the problem.
Alan.
这篇关于Windows窗体控件-启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!