Mark

Mark

  • NA
  • 29
  • 0

Key events not working after button placed in form

Dec 4 2017 7:47 PM
Hi there,
 
I have a program which has a key down event in it.  When the user presses the left, right, up or down arrow keys it basically moves a character around the screen.
 
This program was working fine, however the second i put a button onto the form then the arrow keys all stop working.
 
I have done some research and found some potential solutions, but none of them worked.
 
I have tried the following to form1_load:
keyPreview = true; //turn this on and no key press is registered
this.focus(); //this line doesn't do anything either
this.BringToFront();
this.KeyDown += new KeyEventHandler(Form1_KeyDown);
I have also added the Form1_KeyDown as a trigger to the button control and that didn't seem to fire the Form1_keyDown either.  Any ideas? 
 
As i say, the key presses worked until i placed the button onto the form.  Also when i put a break point in on the key event handler, nothing seems to get triggered.  I think there is conflict between another control but not sure what the next thing to try is?
 
I can supply some code but any help would be greatful.
 
Mark

Answers (6)