Add keyboard shortcuts for buttons in WinForm, ultra-simple, pro-test effective

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.