PC Review


Reply
Thread Tools Rate Thread

Best way to get ctl and alt keys in Panel

 
 
_DD
Guest
Posts: n/a
 
      13th Jun 2006
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.
 
Reply With Quote
 
 
 
 
Barry Kelly
Guest
Posts: n/a
 
      13th Jun 2006
_DD <_(E-Mail Removed)> 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/
 
Reply With Quote
 
=?Utf-8?B?TWluaS1Ub29scyBUaW1t?=
Guest
Posts: n/a
 
      15th Jun 2006
"_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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Handle Arrow Keys in a Panel T Microsoft Dot NET Framework Forms 1 16th May 2007 11:20 PM
Arrow keys work in opposite direction in panel kuchuk Microsoft Dot NET Framework Forms 2 20th Sep 2006 07:03 AM
Missing Registry Keys under HKey_Users\.default\Control Panel... Dan Microsoft Windows 2000 Registry 2 13th Sep 2004 10:11 PM
Missing Registry Keys under HKey_Users\.default\Control Panel... Dan Microsoft Windows 2000 Registry Archive 2 13th Sep 2004 10:11 PM
Remote Desktop "Stuck" Keys and Control Panel NoToSpam ATI Video Cards 0 10th Oct 2003 11:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:53 AM.