<Button Content="Кнопка" Click="Button_Click" IsDefault="True"/>

There is such a button. I want her behavior to be different in cases:

  1. Press Enter.
  2. Shift + Enter pressed.
  3. Ctrl + Enter pressed.

How to implement the Button_Click method in this case?

  • It seems to be necessary to check whether the combination is pressed when clicking on the button. - Veikedo
  • How to implement this check? - ResPasha

1 answer 1

 private void button1_KeyPress(object sender, KeyPressEventArgs e) { if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { MessageBox.Show("Pressed " + Keys.Shift); } } 

Determining Which Modifier Key Was Pressed

  • Thanks, it worked! - ResPasha 2:49 pm
  • @ResPasha, mark the answer as correct. - andreycha