By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,003 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Best way to get ctl and alt keys in Panel

P: n/a
_DD
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.
Jun 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
_DD <_D*@nospam.com> 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.


You can check the state of Control etc. in the MouseDown/MouseMove event
by checking the Control.ModifierKeys static property.

-- Barry

--
http://barrkel.blogspot.com/
Jun 13 '06 #2

P: n/a
"_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.ModifierKeys
static property. For example, to see if the Control key was pressed down
when the mouse was clicked: (Control.ModifierKeys & Keys.Control) != 0. To
check if the ONLY the control key was pressed: Control.ModifierKeys ==
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

Jun 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.