如何在c#中单击鼠标左键时是否按下了ctrl,alt?

时间:2013-01-06 02:50:10

标签: c#

如果在鼠标左键单击 Ctrl Alt ,我想检查我的表单。有没有办法检查它?

2 个答案:

答案 0 :(得分:5)

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))
   {
      // ...
   }
}

答案 1 :(得分:5)

void window_MouseLeftButtonDown_1(object sender, MouseEventArgs e)
{
    if (Control.ModifierKeys == Keys.Control && Control.ModifierKeys == Keys.Alt)
    {
        //...
    }
}