我们可以改变在PropertyGrid中的某个属性的文本/背景颜色我们可以、属性、文本、颜色

2023-09-04 05:02:50 作者:嘎啦嘎啦

我有一个.NET的PropertyGrid控制,显示一些类的属性。我想改变颜色或字体或背景颜色(也没关系只是它们看起来不同于其他显示的属性)的一些属性。我可以编写自定义编辑器做的,但我不知道

I have a .NET PropertyGrid control which displays properties of some class. I want to change the color or font or background color(it doesn't matter just that they look different from the other displayed properties) of some property. I can do with writing custom editor but I was wondering

如果一个更简单的方法是否存在? 如果我用自定义编辑器那么如何更改内置的类型,如BOOL,INT等编辑器。

感谢

推荐答案

没有能够做到。类,它确定如何将项目绘制的PropertyGridView。该人士$ ​​C $ c是有趣的,它几乎做到:

No can do. The class that determines how an item is drawn is PropertyGridView. The source code is interesting, it almost made it:

    private /*protected virtual*/ PropertyGridView CreateGridView(IServiceProvider sp) {
        return new PropertyGridView(sp, this);
    }

不,看起来像在他们决定不制作方法重写的最后一分钟。该PropertyGridView类也被标记为内部。更换所有这些code(存在的很多的它)不是一个现实的选择。

Nope, looks like at the last minute they decided against making the method overridable. The PropertyGridView class was also marked internal. Replacing all this code (there is a lot of it) is not a realistic option.

创建自己的UITypeEditor的内置类型只能通过应用属性到你想要编辑的类的属性。这不是一个通用的解决方案。考虑创建自己的形式,使对象编辑代替。

Creating your own UITypeEditor for built-in types is only possible by applying the attribute to the properties in the class you want to edit. That's not a general solution. Consider creating your own form to make the object editable instead.