Extending Controls Question
Greetings:
I have recently set out to learn how to extend some of the Windows forms controls that are supplied with VS. I'm using C#. Specifically, I wanted ListView to be able to display small images in sub-items ("Detail" mode only), rather than just the left-most item in the list.
I have examined several examples where people have extended ListView and some other controls to make them more versatile and flexible, etc. and I have noticed something that I find puzzling:
Of the ListView examples that I studied 3 of them started by deriving their new class from System.Windows.Forms.Control. This means that they essentially redesigned a list view from the ground up and made it better, instead of deriving their new class from the existing ListView. The code is excessively complicated and difficult to follow for somebody who is new to C# and simply wants to implement a minor extra feature.
The other 2 examples that I studied, did derive their extended class from ListView but BOTH of them ended up importing the User32.DLL and implementing SendMessage calls in order to accomplish what they wanted.
I am in no position to question the wisedom of either approach, I am just a bit surprised with how difficult it is to extend the capability of an existing control without:
A) Starting over from scratch (ie: not extending the original control at all)
B) Resorting to User32 calls
I was led to believe that extending controls was one of the strengths of C#. Why does it seem that in order to add some minor functionality to an existing control, one has to basically break from the .NET environment and haul in imported Win32 calls? Or worse yet, why did 3 of the examples imply that the authors felt so constrained by the control base classes that they simple thought it easier to start over?
Or did I just encounter 5 really bad examples? Somehow, I doubt that.
I welcome any thoughts and reflections that some of you more seasoned programmers may have.
Thank you,
Mark
|