DefaultValue for System.Drawing.SystemColors

I have a line color property in my custom grid control. I want it to be by default Drawing.SystemColors.InactiveBorder. I tried:

[DefaultValue(typeof(System.Drawing.SystemColors), "InactiveBorder")]
public Color LineColor { get; set; }

But that does not work. How to do this with the default attribute?

+3
source share
3 answers

This may help: http://support.microsoft.com/kb/311339 - KB article entitled "MSDN documentation for the DefaultValueAttribute class can be confusing"

+4
source

You need to change the first argument from SystemColorsto Color.
It seems that there is no converter type for the type SystemColors, only for the type Color.

[DefaultValue(typeof(Color),"InactiveBorder")]
+9

According to Matt, the DefaultValue attribute does not set a default value for a property; it simply lets the form designer know that the property has a default value. If you change the default property, it will be in bold in the properties window.

You cannot set the default value using automatic properties - you will have to do it the old fashioned way:

class MyClass
{
    Color lineColor = SystemColors.InactiveBorder;

    [DefaultValue(true)]
    public Color LineColor {
        get {
            return lineColor;
        }

        set {
            lineColor = value;
        }
    }
}
+2
source

Source: https://habr.com/ru/post/1696675/


All Articles