Back to Devexpress

How to: Prevent Specific Shortcuts from Being Processed by the BarManager

windowsforms-5417-controls-and-libraries-ribbon-bars-and-menu-examples-bars-how-to-prevent-specific-shortcuts-from-being-processed-by-the-barmanager.md

latest1.2 KB
Original Source

How to: Prevent Specific Shortcuts from Being Processed by the BarManager

  • Nov 13, 2018

Let us assume, that a form contains the following components:

  • list box
  • Bar Manager with a bar containing the Del bar item which is intended to delete the focused element from the list box. Its shortcut is set to the DELETE key.
  • a text box. Pressing the DELETE key while editing in the text box should clear the selected text

By default, when any control is focused, pressing the DELETE key will always invoke the bar item’s functionality. To prevent this when the text box is focused, we need to handle the BarManager.ShortcutItemClick event.

csharp
private void barManager1_ShortcutItemClick(object sender, 
  DevExpress.XtraBars.ShortcutItemClickEventArgs e) {
    if(e.Shortcut.Key == Keys.Delete)
        e.Cancel = textBox1.Focused;
}
vb
Private Sub BarManager1_ShortcutItemClick(ByVal sender As Object, _
  ByVal e As DevExpress.XtraBars.ShortcutItemClickEventArgs) _
  Handles BarManager1.ShortcutItemClick
    If e.Shortcut.Key = Keys.Delete Then e.Cancel = TextBox1.Focused
End Sub