Nhan Nguyen
Nhan Nguyen

Reputation: 107

Press key and hold event for button in Winform

I'm trying to make a button change its fore color when we press a key. Like button's name is "A" and we press A it changes the fore color into red, then we release the key it turns back to its default color. But I can't find any such event. Thank you! :D

Upvotes: 3

Views: 3275

Answers (2)

Kinetic
Kinetic

Reputation: 2650

If you want to capture a key typed anywhere on a form, you can use Keydown, KeyPress and KeyUp like ydoow said, but you will also have to set the form's KeyPreviewproperty to true to make sure your events are raised even if a key is typed while in a specific control.

Upvotes: 1

ydoow
ydoow

Reputation: 2996

It's KeyDown, KeyPress, and KeyUp event you should use.

Refer to this link.

http://csharp.net-informations.com/gui/key-press-cs.htm

Upvotes: 4

Related Questions