473,379 Members | 1,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Best way to get ctl and alt keys in Panel

_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
2 2281
_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
"_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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: a-ok | last post by:
Hi, My client has a product database od around 20000 items. And it is updated every few days when he gets a catalog from the supplier. It's supposed to work like this: if there already is a...
3
by: Amy L. | last post by:
I have a client / server application. I just want to encrypt small amounts of data 1<x<1024 characters or so. I need to load the same Key and IV in both applications. However, both the key and...
4
by: Neil Wallace | last post by:
Hi there, I have an application in which a grid of 100 or more buttons are put on a form in columns of 10. All the buttons are within a panel. They are added in runtime, and so they adopt a...
11
by: Rlrcstr | last post by:
How can you detect when an arrow key gets pressed? Doesn't seem to trigger a KeyPress or KeyDown event. Thanks. Jerry
2
by: Phil Galey | last post by:
I have a Panel control docked on all sides on a form and the panel control contains a PictureBox. I'm using the KeyDown event of the form to respond to the and keys for resizing the image and the...
1
by: John Salerno | last post by:
Ok, concerning my little pet project...I have int arrays of the following sizes: panel AND panel They are static fields right now, and I'm wondering if it's possible (and better) to make...
6
by: Andre Ranieri | last post by:
Hello everyone, I'm wondering if I could get some advice on the best way to build the user interface depicted in this diagram: http://www.senske.com/images/winforms_layout.jpg The gray areas...
2
by: Horace Nunley | last post by:
A wizard? A formView? I wanna capture about a dozen fields of info, then show a "is this information correct" page, then allow edit or save. Which is the best way? I was thinking I could...
4
by: brett | last post by:
On a postback, what is the best way to get FORM variables so that there is a key/value structure that allows accessing by key name. For example: INSERT INTO table1 (keys, keys) values...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.