如何判断Shift是否在MouseDown事件中被按下? [英] How to tell if Shift is being pressed in a MouseDown event?
问题描述
我在控件上捕捉到一个 MouseDown
事件,这给我在签名中提供了一个 MouseEventArgs
对象。现在我想要能够判断用户是否按住Shift或Control键。但是 MouseEventArgs
对象不包含任何键盘信息!
I am catching a MouseDown
event on a control, which gives me a MouseEventArgs
object in the signature. Now I want to be able to tell if the user was holding down the "Shift" or "Control" key when they clicked. But the MouseEventArgs
object doesn't contain any keyboard information!
最简单的方法是告知键盘<
What's the easiest way of telling whether the keyboard Shift/Ctrl keys were being held at the time of the click?
推荐答案
p>使用Controls.ModifierKeys属性来查看按下的内容。例如:
Use the Controls.ModifierKeys property to see what's pressed. For example:
private void Form1_MouseClick(object sender, MouseEventArgs e) {
if (Control.ModifierKeys == Keys.Control) {
Console.WriteLine("Ctrl+Click");
}
}
其他修饰符是键。 Alt
和 Keys.Shift
。查找与(Keys.Control | Keys.Shift)
的组合。
Other modifiers are Keys.Alt
and Keys.Shift
. Find combinations with, say, (Keys.Control | Keys.Shift)
.
这篇关于如何判断Shift是否在MouseDown事件中被按下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!