On Thu, 14 Aug 2008 09:12:27 -0700, sundarvenkata
<su***********@gmail.comwrote:
I see your point. But doing so defeats the reusability of the
UserControl. Every time I use this control in some other form, I need
to ensure that the parent control calls the appropriate methods in the
child control to handle keyboard events. Is it possible to scope the
key handling such that it is handled only by the user control and not
passed up the control hierarchy?
Maybe I misunderstood your question. If you only want the UserControl to
handle the keyboard input, then what do you mean by "to have key bindings
that apply to every instance of the user control"? The way I read that,
you want a single key input to cause something to happen in every instance
of the UserControl that you've made.
Are you saying that's not actually what you want? If so, could you
elaborate on what's wrong with the default "cycle through the buttons"
behavior?
If I didn't misunderstand, then I think you could implement this in the
UserControl only, but I would say that would be a bad design. In
particular, of course any given UserControl receiving key input could
inspect all of the children of its parent to see if there are other
UserControl instances that it can forward the key input to. But then what
happens when someone wants to use more than one of those UserControl
instances in a situation when they _don't_ want that behavior?
Putting the logic in the parent seems to me to be a simpler, more
adaptable, more sensible design.
Pete