0

I have hosted 2 usercontrols hosted on a windows form each having a save, delete button with &Save, &Delete shortcut key. when I am focusing Usercontrol1 and press ALT+S, it invokes usercontrol2 save button event handler. appreciate your suggestion to fix this.

Gururaj
  • 1,115
  • 2
  • 14
  • 17

1 Answers1

0

You should override the ProcessCmdKey() method in your control:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) 
{
}

"If the command key is not a menu shortcut and the control has a parent, the key is passed to the parent's ProcessCmdKey method." (Source: MSDN)

Or you could do the same at the Form level, and then route the command to the proper control by checking the one that has the focus. To find the focused control, refer to this SO question: What is the preferred way to find focused control in WinForms app?

Community
  • 1
  • 1
vulkanino
  • 9,074
  • 7
  • 44
  • 71