Working out if Control button is down in MouseDown event

1

100

Hi JezB
In MouseDown handler check the Control.ModifierKeys static property here you
can find the states of ALT, CTRL and SHIFT keys.

HTH
B\rgds
100
 
S

Saurabh

You mean something like,
if ((ModifierKeys & Keys.Control) == Keys.Control) //check if Ctrl key was
pressed, note bitwise &

cheers!!

--Saurabh
 
N

n!

How can this be done ? There's no Keys attribute in MouseEventArgs.

System.Windows.Forms.Control has a static 'ModifierKeys' property you can
access:

e.g.

using System.Windows.Forms;

....
if ( Control.ModifierKeys == Keys.Control )
{
// CTRL key was pressed (and no other modifier)
}
....

n!
 
T

Tim Wilson [MVP]

Use the static ModifierKeys property of the Control class:

if (Control.ModifierKeys == Keys.Control)
{
// then the Ctrl key is down.
}
 
J

JezB

Typical !! Loads of people answer when you find the answer yourself - when
you are really stuck no-one gives a solution !! hehe
 
H

Herfried K. Wagner [MVP]

* "Tim Wilson said:
Use the static ModifierKeys property of the Control class:

if (Control.ModifierKeys == Keys.Control)
{
// then the Ctrl key is down.
}

If you want to check if the control key is down even when other modifier
keys are down, use this code:

\\\
If Control.ModifierKeys And Keys.Control Then
...
End If
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top