You need to add an eventhandler-method to the
KeyDown
-event of the control(s) for which you want to recognize this. You can do this either through the Designer via Properties > Events or manually. Example here for a TextBox-Control:
SomeTextBox.KeyDown += SomeTextBox_KeyDown;
private void SomeTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Z && e.Modifiers == Keys.Control)
{
}
}
If you want to process this event for more than one control, you can add the same eventhandler-method to the events of many controls:
SomeTextBox.KeyDown += SomeControl_KeyDown;
SomeOtherTextBox.KeyDown += SomeControl_KeyDown;
SomeOtherControl.KeyDown += SomeControl_KeyDown;
In that case, if you want to know from which control the event originated, you have to look at the argument
sender
which will be a reference to that control.
If you want to receive that event also for the Form itself you have to set its property
KeyPreview
to true.