C# custom control default value property

0

I have the following problem:

I have built a custzom control with various properties. For easiert ui design I want to add default values to my properties. This works fine with objects but not with colors.

This is my property:

[Browsable(true)]
[Category("Custom Colors")]
[Description("Gets or sets the line color if not focused.")]
//[DefaultValue(typeof(Color), "61, 81, 181")]
//[DefaultValue(typeof(Color), "31, 0, 0, 0")]
public Color LineColor
{
    get { return _lineColor; }
    set { _lineColor = value; }
}

The method with three RGB values "61, 81, 181" is working fine. But how can I achieve the same result with four ARGB values like "31, 0, 0, 0" ?

I tried using a hex string. This is also working with RGB "0x3d51b5" but not with ARGB "0x1f000000" or "0x0000001f".

c#
.net
properties
custom-controls
asked on Stack Overflow Mar 3, 2018 by Tobias Wälde

1 Answer

0

you can initialize the _lineColor with the default color, yhen the default value on LineColor as _linecolor:

    private Color _lineColor = Color.FromArgb(50, 200, 0, 100);

    public Color LineColor
    {
        get { return _lineColor; }

        set {

            _lineColor = value == Color.Empty ? Color.FromArgb(50, 200, 0, 100): value;
        }

    }
answered on Stack Overflow Mar 3, 2018 by henoc salinas • edited Mar 3, 2018 by henoc salinas

User contributions licensed under CC BY-SA 3.0