简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM