Bloggers do not have many Windows platform under the development experience of the program, a year ago, the use of MFC designed a Fingerprint Identification System page, and then did not use a few times. Now the C # Course experiment requires a simple calculator, which makes it much more efficient to use a keyboard than a mouse click button for fast data entry. For example, press the Numpad number 1, can achieve and with the mouse click button 1 the same effect on the line.
Baidu once again, found the tutorial is almost exactly the same, a variety of csdn reprinted on the blog has provided several methods, but tried not a useful, do not know where the configuration error. Then Google a bit, click the first search results, StackOverflow question and answer, successfully solved my problem.
To implement a custom keyboard key, just overwrite protected override bool processCmdKey (ref Message msg, Keys KeyData) This method (function) is good.
protected Override BOOLprocessCmdKey (refMessage msg, Keys keyData) { //if it is a hotkey, return true; otherwise, return false Switch(keyData) { Casekeys.numpad0://Focus is positioned on the control button_num_0, which is the number 0 keyButton_num_0.focus (); //perform button click actionButton_num_0.performclick (); return true; CaseKeys.NumPad1:button_num_1.Focus (); Button_num_1.performclick (); return true; //...... default: Break; } return Base. processCmdKey (refmsg, keyData);}
For a complete sample code of the project, please see this article: http://www.cnblogs.com/zyfdeblog/p/4567071.html:
Original article, please attach the original address when reproduced. Thank you.
Add keyboard shortcuts for buttons in WinForm, ultra-simple, pro-test effective