1

I have to catch the event when I pressed on Shift Tab in TextBox to write some code. It is possible to do that? I tried with that test on KeyUp event :

    private void txtJustifTampon_KeyUp(object sender, KeyEventArgs e)
    {
     if (e.KeyCode == Keys.Tab && Control.ModifierKeys == Keys.ShiftKey)
        {
            //do stuff
        }            
    }
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
ucef
  • 557
  • 3
  • 10
  • 27

1 Answers1

1

One of the possible ways out is to use PreviewKeyDown instead of KeyUp since

Some key presses, such as the TAB, RETURN, ESC, and arrow keys, are typically ignored by some controls because they are not considered input key presses

private void txtJustifTampon_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
  // If Shift + Tab pressed (i.e. Tab with Shift modifier) 
  if (e.KeyCode == Keys.Tab && e.Modifiers == Keys.Shift) {
    //TODO: put relevant code here (do stuff)
  }
}

Please, notice that we should use Keys.Shift (not Keys.ShiftKey) as the modifier and we should apply modifier to the event argument (e.Modifiers)

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215