开发者

PropertyGrid, DefaultValue, Unknown Colors

开发者 https://www.devze.com 2022-12-16 02:19 出处:网络
To Any...To All, My property grid is 开发者_如何学运维inspecting a class that has several color properties...

To Any...To All,

My property grid is 开发者_如何学运维inspecting a class that has several color properties...

The colors are not system colors, nor 'Known' colors...

When displaying the colors the text value in the grid might look like this:

209, 175, 171

How do I define [Attribute] the Property so that when this color is chosen, the PropertyGrid understands that the default color has been chosen?

I have tried:

[DefaultValue(typeof(Color),"209 , 175, 171")]
[DefaultValue(typeof(Color),"209,175,171")]

No luck so far...

Thanks for any help...

This site rocks...it has helped me more than any other site as I trudge through this project...

Carson


I just tried this in a Windows Forms app and it works fine. Here is my entire app:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e) {
        propertyGrid1.SelectedObject = new Foo();
    }
}

public class Foo {
    [DefaultValue("foo")]
    public string MyString { get; set; }

    [DefaultValue(typeof(Color), "209 , 175, 171")]
    public Color MyColor { get; set; }
}

And my form is a default form with a PropertyGrid control on it.

When the color is set to 209,175,171 it shows in normal text. If I change any value it shows up as bold. Similarly, when the string is set to any text it's bold and when I set it to "foo" then it shows in normal text.

With non-default values:

PropertyGrid, DefaultValue, Unknown Colors

With default values:

PropertyGrid, DefaultValue, Unknown Colors


Same problem here. DefaultValue(typeof(Color) is not working for me.

I have to do this:

private void Form1_Load(object sender, EventArgs e)
    {
        MyCar car1 = new MyCar();
        this.propertyGrid1.SelectedObject = car1;
    }

    public class MyCar{
        //*****************************
        private Color MyColor_ = Color.Red;//<------------------------ Here
        //*****************************
        public Color MyColor
        {
            get { return MyColor_; }
            set { this.MyColor_ = value; }
        }

        private String Id_;
        public String Id
        {
            get { return Id_; }
            set { this.Id_ = value; }
        }

    }

PropertyGrid, DefaultValue, Unknown Colors

It works for me, I don't know where is the problem exactly.

0

精彩评论

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