I am building a tool using C#. It's a Windows application. I have one text box on a form, and I want to assign focus to that text box when the user presses Ctrl + F or Ctrl + S.
How do I do this?
I am building a tool using C#. It's a Windows application. I have one text box on a form, and I want to assign focus to that text box when the user presses Ctrl + F or Ctrl + S.
How do I do this?
Add an event that catches a key press on the form, analyse the key press and see if it matches one of your shortcut keys and then assign focus.
Capture the
KeyDown
event and place an if statement in it to check what keys were pressed.One way is to override the ProcessCMDKey event.
EDIT: Alternatively you can use the keydown event - see How to capture shortcut keys in Visual Studio .NET.
1st thing Make sure that the Your Windows Form property is "KeyPreview=true"
2nd Thing Open Form Event Property And double click on "KeyDown" And Write The Following code inside The Body of Event:-