【发布时间】:2013-01-09 20:28:01
【问题描述】:
如果在单击鼠标左键时按下了 CtrlAlt,我想检查我的表单。有什么方法可以检查吗?
【问题讨论】:
-
这取决于您正在制作的应用程序的类型。它是控制台应用程序吗? Windows 窗体应用程序? WPF 应用程序? WinRT 应用?
标签: c#
如果在单击鼠标左键时按下了 CtrlAlt,我想检查我的表单。有什么方法可以检查吗?
【问题讨论】:
标签: c#
void window_MouseLeftButtonDown_1(object sender, MouseEventArgs e)
{
if (Control.ModifierKeys == Keys.Control && Control.ModifierKeys == Keys.Alt)
{
//...
}
}
【讨论】:
WPF: 在 xaml 中将事件添加到您的窗口:
MouseLeftButtonDown="window_MouseLeftButtonDown_1"
或在后面的代码中:
public MainWindow()
{
InitializeComponent();
this.MouseLeftButtonDown += window_MouseLeftButtonDown_1;
}
然后你可以检查回调中的按键
private void window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.LeftAlt))
{
// ...
}
}
【讨论】: