What to extend for a new custom control?

c#, user-controls, winforms

Solution

I think the unofficial and accepted "standard" is to just inherit from `UserControl`. At least that's what I've seen everywhere else. That does not make it the right thing though!

On the other hand, I think you also may be too concerned about the "right thing" to do here. To me, this is almost similar to premature optimization. You want to make sure that you spend your resources wisely.

Also keep in mind that things like this can always be changed later.

If you're concerned for a reason, I would definitely pick the simplest of the controls with the lowest inheritance depth.

Problem

Some people suggest to just extend `Panel` but I also know about `UserControl` that sounds like something I should extend to make my own control. `Panel` vs. `UserControl` vs. `Control` vs. `another_alternative` ``` // inheritance depth: Control Panel : ScrollableControl : Control UserControl : ContainerControl : ScrollableControl : Control ``` All I need is a rectangle to draw and full WinApi ability (Handle, WndProc etc.). But I want to avoid all the extras that might come into the play. I want to use my custom controls to add them to standard forms. No extreme actions. On the other hand UserControl extends ContainerControl that might have functionality I want (I'm not sure). I inherited from `Control` for an OpenGL box and some other simple controls. They work fine so far. I haven't noticed any functionality-loss. Does something speak against `Control` ? (in case I don't require any extra functionality)

Original source