更改只读属性前景色在PropertyGrid中 [英] Change the foreground color of read-only properties in a propertygrid

查看:157
本文介绍了更改只读属性前景色在PropertyGrid中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的WinForms属性网格显示对象的属性。然而,大部分属性是只读的,因此显示为灰色而不是黑色。有没有一种方法来定制所使用的颜色?我想残疾人的属性是有点更容易阅读。

I'm using a WinForms property grid to display the properties of an object. However, most of the properties are read only and thus show up as grey rather then black. Is there a way to customize the colors that are used? I'd like the disabled properties to be a bit easier to read.

BTW:我认为答案<一个href="http://stackoverflow.com/questions/136129/windows-forms-how-do-you-change-the-font-color-for-a-disabled-label">this问题可能与我想要做的。但我不知道究竟如何,我可以访问 ControlPaint.DrawStringDisabled

BTW: I think the answer to this question might be related to what I'm trying to do. But I'm not sure exactly how I can access ControlPaint.DrawStringDisabled.

推荐答案

不幸的是,没有内置的方式来改变颜色。与很多标准的.NET控件,它们仅仅是包装自己的COM当量的版本。

Unfortunately, there's no built-in way to change the colour. As with a lot of the standard .NET controls, they're merely wrapped versions of their COM equivalents.

这意味着在实践中,很多的画,如果不是全部由COM组件完成的,因此,如果您尝试重写.NET 的OnPaint 方法调用 ControlPaint.DrawStringDisabled 或其它任何绘画code,它更可能将有不良影响,或没有影响什么那么以往任何时候。

What this means in practice is that a lot, if not all of the painting is done by the COM component, so if you try overriding the .NET OnPaint method and calling ControlPaint.DrawStringDisabled or any other painting code, it's more than likely going to have an undesired effect, or no effect what-so-ever.

您的选择是:

  1. 从头开始建立一个自定义的控制(可能是最简单的)
  2. 覆盖的WndProc ,并试图拦截漆消息(不能保证工作)
  3. 在试图重写的OnPaint ,做你的画在上面(不能保证工作)
  1. Build a custom control from scratch (probably the easiest)
  2. Override WndProc and try to intercept paint messages (not guaranteed to work)
  3. Attempt to override OnPaint and do your painting on top (not guaranteed to work)

对不起这可能不是你想要的答案,但我想不出一个更简单的方法。我从痛苦的经验中知道,这样的事情是很难修改。

Sorry that's probably not the answer you wanted, but I can't think of an easier method. I know from bitter experience that this sort of thing can be hard to modify.

这篇关于更改只读属性前景色在PropertyGrid中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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