"_DD" wrote:
I'm trying to gracefully intercept Control and Alt keys for mouse
events within a Panel. I realize that keyboard is not normally
relevant there, but in this case, I need to get Ctrl-LeftMouseButton ,
etc.
This could be intercepted by the form that owns the panel, but that
does not seem very elegant. Are there any alternatives? I could use
another type of base control if necessary. I'm mostly painting
graphics.
If you are trying to determine which modifier keys are pressed when the user
clicks the mouse in your panel: Subscribe to the Panel's MouseDown event.
Then in your event handler, check the status of the Control.Modifie rKeys
static property. For example, to see if the Control key was pressed down
when the mouse was clicked: (Control.Modifi erKeys & Keys.Control) != 0. To
check if the ONLY the control key was pressed: Control.Modifie rKeys ==
Keys.Control.
But if you want to check the state of the modifier keys at a random time
(i.e., not when the mouse was clicked) your job is more difficult because the
panel will only receive key events when it has focus. Since it's not
normally a control that receives focus nor shows that it has focus, this is
tricky. Instead, you can set the form's property form.KeyPreview =true. This
tells the form to intercept key events for all of its child controls before
passing the events on to the focused control. Then subscribe to the form's
KeyDown event to catch all key presses.
--
Timm Martin
Mini-Tools
..NET Components and Windows Software
http://www.mini-tools.com