I have a TextBox on a WinForm and I want to execute some code every time someone presses a key inside of that TextBox. I’m looking at the events properties menu, and see the KeyDown event, but don’t know how to add code to it.
I have a TextBox on a WinForm and I want to execute some code
Share
You need to add an event handler for that event. So in the properties menu, double-click on the field beside the KeyDown event and Visual Studio will create an event handler for you. It’ll look something like this:
You can also subscribe to events yourself without using the Properties window. For example, in the form’s constructor:
And then implement the event handler: