Guys hi there))
pleace tell me - Is this default attribute correct (it doesn't work in my costom control) -

[Bindable(true), Category("BrushOptions"), Description("end color"), DefaultValue(typeof(Color), "White")]
            public Color EndColor
            {
                get { return endColor; }
                set { endColor = value; OnChangeProperties(); }
            }

thanks in advance))

Recommended Answers

All 11 Replies

If you are having problems a good idea is always to step back and try and isolate the it. Initialize the property in the constructor to see if that is the problem.

commented: +++++++++ +3
[DefaultValue("Color.White")]

[DefaultValue("Color.White")]

thit doesn't work too.

[DefaultValue("Color.Red")]
            public Color MainColor
            {
                get { return mainColor; }
                set { mainColor = value; OnChangeProperties(); }
            }

humm.. i have been using this code for quite a while and it works fine..

may be if you can provide full code than i can help you here..

commented: +++++++ +3

project has been attached))

i see ..

but one workaround can be done like this:
when you declar the start,end colors , give them the Default color values.
like

private Color startColor = Color.Green;
private Color endColor = Color.Blue;
private Color mainColor = Color.Red;

this colors will act as defaults.. i have tested and it's working fine..

commented: ++++++++ +3

i agree with you about this code. but why the default atribute doesn't work?....

DefaultValue attribute does not set the initial value of property. The VS designer will display this value as non-bold (defaultValue) and other values as bold (which are modified), but still you have to set the value of this property.

but still you have to set the value of this property.

why? for default value?)

Yes, I think it is right

commented: +++++++ +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.