How can I determine when control key is held down during button click

后端 未结 2 776
我在风中等你
我在风中等你 2020-12-30 04:41

How can I determine when the control key is held down during button click in a C# Windows program? I want one action to take place for Ctrl/Click and a different one for Cli

2条回答
  •  旧巷少年郎
    2020-12-30 05:43

    Assuming WinForms, use Control.ModifierKeys, eg:

    private void button1_Click(object sender, EventArgs e) {
        MessageBox.Show(Control.ModifierKeys.ToString());
    }
    

    Assuming WPF, use Keyboard.Modifiers, eg:

    private void Button_Click(object sender, RoutedEventArgs e) {
        MessageBox.Show(Keyboard.Modifiers.ToString());
    }
    

提交回复
热议问题