Thursday, 13 November 2014

c# WPF - Detecting Key Presses - Example: Detecting CTRL+C in a TextBox

The following example allows you to override the keyboard shortcut for copy (Control + C) on the KeyDown event of a WPF TextBox control.

Code Snippet
  1. private void TEXTBOX_KeyDown(object sender, KeyEventArgs e)
  2. {
  3.     if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control)
  4.     {
  5.         MessageBox.Show("CTRL + C has been pressed!");
  6.     }
  7. }
End of Code Snippet

No comments: