-1

I have a flowlayoutPanel with about 50 userControl added dynamically.

I use this.KeyPreview = true in the form to be able to catch event in the form. As it is now I use this eventhandler:

private void Form1_KeyDown(object sender, KeyEventArgs e)
{    
}

for KeyDown to be able to catch spacebar, the + character and the navigation key pageUp and pageDown. This works good.

I also need to catch the navigation arrowUp and arrowDown but the only working solution for me is to use an event handler for KeyUp like this. When I use event handler Form1_KeyUp event I can use the navigatiobn key arrowUp and arroeDown.

 private void Form1_KeyUp(object sender, KeyEventArgs e)
 {          
 }

I tried to use this event handler

private void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{    
}

but this is never called when I click the navigation arrowUp and arrowDown.

I hope to be able to catch everything such as (pageUp, pageDown, spacebar, + character arrowUp and arrowDown) in the event handler for KeyDown

Any help is welcome.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
tony
  • 127
  • 1
  • 1
  • 7
  • When I use the navigation key pageUp, pageDown, arrowUp and arrowUp I have the UserControl within the flowlayoutPanel as acive contrfol. – tony Sep 20 '16 at 12:53

1 Answers1

0

It's simpler to just override the ProcessCmdKey function:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
  if (keyData == Keys.Up) {
    // do something here
    return true;
  } else {
    return base.ProcessCmdKey(ref msg, keyData);
  }
}
LarsTech
  • 80,625
  • 14
  • 153
  • 225