Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Press key and hold event for button in Winform

Tags:

c#

winforms

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

like image 834
Nhan Nguyen Avatar asked Dec 01 '25 17:12

Nhan Nguyen


2 Answers

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

Refer to this link.

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

like image 178
ydoow Avatar answered Dec 04 '25 06:12

ydoow


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.

like image 28
Kinetic Avatar answered Dec 04 '25 06:12

Kinetic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!