I have a containercontrol with some buttons. The buttons are instances of my own button class (canvas plus a nice paint event to draw the button). So far so good. Now, I want to be able to rearrange these buttons at runtime, by drag/drop. Canvas seems to have enough events to do this, but no action event per se, so I need to put the action code in the button’s own MouseDown event, and apparently also the drag-initiation code. Trouble with this is that the drag starts on mousedown, and so the button image (which will be dragged) shows even if I’m just clicking the button to do the button’s action.
To get round this I need the MouseDown event to either do the action, or do the drag-initiation, but never both at once. This will be mediated by a property that gets set elsewhere. This is easy enough, but I only see two ways to do this and each has a disadvantage.
have the property belong to the containercontrol. But as far as I can see this forces each button to have its own MouseUp and MouseExit events, rather than hiding those away in the button class. These two event handlers always have the same code so they could go there. They are both quite short but it’s not their length but that I need to make sure that 30 buttons have these handlers.
have the property be in the button class, which would allow the event handlers to be there too. Downside of this is that then when switching the containercontrol between normal operation mode and configuring-it mode, I’d then have a large number of instances of the property to change. Still, I’m minded to do it this way as I can automate that reasonably easily.
What I’m wondering is whether I’ve simply overlooked some aspect of how classes and instances thereof work.