"TomC" <to*********@bigfoot.comwrote:
>In this case, I don't see any way to get around using inheritance.
What I want to do is create a custom visual display, so I need to
customize some sort of object that can be displayed visually.
Right, there are two types of customizations: (1) by the creator of
the application, who normally customizes by adding events instead of
by inheriting; (2) by the middleware/componentware author who creates
new components through inheritance.
Wearing your application-creator hat, you'd plonk down a PictureBox on
your form, one for each square. You'd probably just set its "Image"
property to the image (draughtspiece, chesspiece, blank...). Or you
could override its OnPaint event. That's to say, OnPaint is a list of
method+instance-pointers, and you will make it point to the
ChesspiecePaint method of your MyForm, and your MyForm will contain
the logic for painting it. Maybe you'd use its "tag" property to store
its coordinates or something like that.
Wearing your componentware-author's hate, you'd inherit from
PictureBox and add any properties that you see fit.
>It needs to have the the ability to draw on itself
So the .net/winforms philosophy is that often it's the
application/form that has the ability to draw the unusual controls it
uses, and which has the ability to respond to their clicks. Instead of
the java philosophy where it's normally the control itself that knows
how to paint itself.
--
Lucian