David_Try_Everything
David_Try_Everything

Reputation: 101

Make the form always get focus even i click another control in C#

I made a game with multiple forms in C#

The game use picturebox and button I use key down event in form with arrow key to make picturebox move...

The problem occur when I click a button that display hidden groupbox. The button get a focus and when I press my keys to move the picturebox, the picturebox doesn't move. But the focus ring in button move to another button when I press my keys.

I tried clicking my form, set this.focus() and this.select in button click But nothing above work..

Please help me, this game must be done this saturday.

Upvotes: 2

Views: 776

Answers (1)

Jon
Jon

Reputation: 3255

Sounds like homework :)

Try setting Form.KeyPreview = true;  

This will catch all your key presses, regardless of what control has focus.

Upvotes: 1

Related Questions