hetelek
hetelek

Reputation: 3896

Setting default values for properties in C#

I am creating a simple control in C#, and I have come across a problem. I have created 2 properties for my control(it's a button), and the 2 properties are GradientColor1 and GradientColor2. The only problem I am having while creating these, is that I do not know how to set them to have a default property. I know I could do:

GradientColor1 = Color.Black;
        GradientColor2 = Color.DarkGray;

Under my constructor, but I want it so they have the ability to click the 'Reset' item in the context menu under the properties panel. As you can see, right now it's disabled:

https://i.sstatic.net/ds3AA.png - Can't post images yet.

Upvotes: 0

Views: 202

Answers (1)

Brent M. Spell
Brent M. Spell

Reputation: 2267

I verified that attributing your property with the DefaultValueAttribute will enable the Reset menu item. However, you will also need to initialize the value of the property in the constructor.

Upvotes: 1

Related Questions