Tobias Wälde
Tobias Wälde

Reputation: 70

C# custom control default value property

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".

Upvotes: 0

Views: 707

Answers (1)

henoc salinas
henoc salinas

Reputation: 1054

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

    }

Upvotes: 1

Related Questions