Color Property in C#

  • Thread starter Thread starter Yoshi
  • Start date Start date
Y

Yoshi

Hi Everyone!

I would like to create a "color" property on my form called CarBackColor. I
want this property to show up in the Properties window in VS.Net.

I want to use the SystemColors. Can someone point me in the right
direction?

Thanks,

Yoshi
 
I believe you derive your form (MyForm) from Form. If so, add this [C#]:

private Color carBackColor;


[Browsable(true), Category("MyForm")]
public Color CarBackColor{
get { return carBackColor; }
set {
// accept only SystemColors
if (value.IsSystemColor) carBackColor = value;
}
}

However, this approach still shows all colors in the property window. If you
want to change it, you'll need to create own property designer.
 
Back
Top