测试如果Ctrl键是向下使用C# [英] Test if the Ctrl key is down using C#
本文介绍了测试如果Ctrl键是向下使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格,用户可以双击鼠标,它会做什么。现在,我希望能够知道用户是否还持有<大骨节病>控制骨节病>键,在表单上的用户双击。
I have a form that the user can double click on with the mouse and it will do something. Now I want to be able to know if the user is also holding the Ctrl key down as the user double click on the form.
如何才能知道,如果用户持有<大骨节病>控制骨节病>键不放?
How can I tell if the user is holding the Ctrl key down?
推荐答案
使用.NET 4,你可以使用简单的东西是:
Using .NET 4 you can use something as simple as:
private void Control_DoubleClick(object sender, EventArgs e)
{
if (ModifierKeys.HasFlag(Keys.Control))
{
MessageBox.Show("Ctrl is pressed!");
}
}
如果你不使用.NET 4中,则可获得 Enum.HasFlag
被撤销,但要实现在previous版本相同的结果:
If you're not using .NET 4, then the availability of Enum.HasFlag
is revoked, but to achieve the same result in previous versions:
private void CustomFormControl_DoubleClick(object sender, EventArgs e)
{
if ((ModifierKeys & Keys.Control) == Keys.Control)
{
MessageBox.Show("Ctrl is pressed!");
}
}
这篇关于测试如果Ctrl键是向下使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文