user850010
user850010

Reputation: 6359

Easiest way to add custom properties to existing controls in winform?

I have a grid of Panel Controls in Winform. I would like for those panels to contain a custom string and custom int property.

What would be the easiest way to achieve that? One way would probably be extending the Panel control, but I do not want to do big changes to the control, just to add 2 custom properties.

I am using .NET 4.0

Any pointers you can give to me will be appriciated.

Upvotes: 0

Views: 155

Answers (2)

LarsTech
LarsTech

Reputation: 81620

You answered your own question:

One way would probably be extending the Panel control...

Just add your properties and start using the control.

Upvotes: 1

Gregory A Beamer
Gregory A Beamer

Reputation: 17010

If these are properties of the class, then deriving from Panel and creating a custom implementation are the best bet, especially if you are using this on multiple forms or multiple projects. You could "cheat" by adding extension methods, but setting up individual getter and setter methods to implement properties is a bit more pain than you have to go through.

Upvotes: 1

Related Questions