0

I am using Winforms dialog with multiple tabs (tab1 and tab2). Both of the tabs have KeyPreview = true.

On tab1 when I hit W on my keyboard, the KeyDown (for tab1) event triggers successfully. However upon switching to tab2 and then back to tab1, the same key does not trigger anymore.

Any idea on what is causing the problem?

John Tan
  • 1,331
  • 1
  • 19
  • 35
  • Could be that the tab header has input focus? –  Oct 14 '15 at 02:09
  • @Micky How do I check for input focus? – John Tan Oct 14 '15 at 02:10
  • 1
    http://stackoverflow.com/questions/1814209/fastest-way-to-get-focused-control-in-winforms-c –  Oct 14 '15 at 02:26
  • KeyPreview is a property of the Form class. Which has absolutely nothing to do with tabs so the question makes little sense. KeyPreview is a hokey VB6 compatibility property, override ProcessCmdKey() to do it the .NET way. – Hans Passant Oct 14 '15 at 08:41

1 Answers1

0

I found a method around this:

Basically in the OnClick method in tab1, I simply call this.Focus().

So the user has to click back onto the tab page, and he will be able to press a keyboard command after this.

John Tan
  • 1,331
  • 1
  • 19
  • 35