更改TextBox的默认禁用前景色 [英] Change the default disabled fore color of TextBox

查看:82
本文介绍了更改TextBox的默认禁用前景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想更改TextBox的默认禁用前色而不覆盖

Hi,
I want to change the default disabled fore color of TextBox without overriding

OnPaint()

方法。有什么想法吗?



如何在我的TextBox的

method. Any Idea?

How can I handle WM_CTLCOLOREDIT and WM_CTLCOLORSTATIC message notifications in

WndProc()

中处理WM_CTLCOLOREDIT和WM_CTLCOLORSTATIC消息通知改变前景颜色?。

of my TextBox to change the forecolor ?.

推荐答案

在深入研究Win API之前,您可能会考虑如果设置Control的BackColor,然后禁用它,它显示一个略微褪色的BackColor,而不是启用控件。



我建议你尝试这个实验:创建一组四个按钮与BackColors如:



250,200,200 //淡红色

200,250,200 //淡绿色

250,250,200 //淡黄色

200,250,250 //淡蓝色



将他们的Enabled Property设置为'false。



将它们全部复制,粘贴,然后将它们并排放置,这样就可以得到另一个相同的设置:设置副本的启用属性to'true;



现在,运行Appli阳离子并比较/观察差异。



是否可以通过简单地使用BackColor属性来满足您通过颜色区分禁用控件的需求?
Before you go to the trouble to dig into the Win API, you might consider the fact that if you set a Control's BackColor, and then disable it, it shows a slightly faded BackColor than it does if the Control is enabled.

May I suggest you try this experiment: create a set of four Buttons with BackColors like:

250, 200, 200 // pale red
200, 250, 200 // pale green
250, 250, 200 // pale yellow
200, 250, 250 // pale blue

Set their Enabled Property to 'false.

Copy them all, and paste, and put them side-by-side, so you have another, identical, set: set the copies' Enabled Property to 'true;

Now, run the Application and compare/observe the difference.

Is it possible that you could meet your needs for differentiating disabled Controls by Color by simply using the BackColor Property ?


这只是解决方案#1扩展的几个选项。



我猜你不喜欢灰色的forecolor用于禁用文本框。



如果是这种情况,您可以尝试使用 ReadOnly 属性进行试验。它保持文本黑色。



另一种可能性是保持文本框启用并处理KeyPress事件,如下所示:

This is just few more options as extension to the solution #1.

I guess you don't like grey forecolor for disabled textbox.

If that the case, you might try to experiment with ReadOnly property. It keeps text black.

Another possibility is to keep text box enabled and handle KeyPress event like shown below:
private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
    e.Handled = true;
}





最后第三个选项:覆盖 OnPaint 。我知道你排除了它,但如果你想用其他属性或非标准行为来增强你的文本框,你就会注意到它。



And finally third option: overriding OnPaint. I know you ruled it out, but thee is noting wring with it at all if you want to enhance your text box with additional properties or non standard behavior.


这篇关于更改TextBox的默认禁用前景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆