Dovahkiin
Dovahkiin

Reputation: 257

C# WFA - Can't move with arrow keys after clicking on button

I have a picturebox which is moved around the form with the arrow keys. (Using the Key_Down and Key_Up events). While moving the pbx, if space is pressed on top of a certain label, a button appears.

The problem is that after clicking on the button, I can't move the pbx with the arrow keys again, unless I click outside the form and then click back into it.

I tried

private void btnAnswer1_Click(object sender, EventArgs e)
        {
            // Button code
            this.Activate();
        }

to refocus the form after clicking on the button, but it didn't seem to do anything.

Help is much appreciated!

Upvotes: 0

Views: 73

Answers (1)

Rickless
Rickless

Reputation: 1455

I assume you didn't use Form.KeyPreview Property. If you set this property to True in the form constructor. The form event handlers should able to receive the event properly.

When this property is set to true, the form will receive all KeyPress, KeyDown, and KeyUp events. After the form's event handlers have completed processing the keystroke, the keystroke is then assigned to the control with focus.

Upvotes: 1

Related Questions