开发者

Can we change the text/background color of an individual property in 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:

  1. If an easier method exists?
  2. If I use custom editor then how do i change the editor of built-in t开发者_StackOverflow中文版ypes like bool, int etc?


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);
    }

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.

Creating your own UITypeEditor for built-in types is only possible by applying the [Editor] 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜