Ways to define shortcut keys
//write on the Form_Load when the //indicates that the form accepts key events //and then writes the following code in the KeyDown event to implement whether the input is CTRL + A key combination: private void form1_keydown (object sender, keyeventargs e) { if (e.keycode == keys.a & & e.modifiers == keys.control) messagebox.show ("Ctrl+r"); } //verify that the input is not a combination keyboard ctrl+a protected override bool processcmdkey (ref message msg, keys KeyData) { if (keydata == ( KEYS.CONTROL | KEYS.A)) { messagebox.show ("Ctr+a"); } retuRn base. processCmdKey (ref msg, keydata); } //or use the general key to handle it. protected override bool processdialogkey (Keys keydata) { if (keydata == (KEYS.CONTROL | KEYS.A)) { MessageBox.Show ("Ctr+a"); } Return base. processDialogKey (keyData); } // Get user-defined key combinations from an external configuration file: XML, for example, processCmdKey protected override bool processCmdKey (Ref message msg, keys keydata) { //get a list of shortcut keys &nbsP; string shortcutkeys = xmlhelper.xmlread2 (XmlPath, " Shortcutkeys ") //assume that the key is connected with the key by the + sign string[] keyStrs = Shortcutkeys.split (' + '); keys combinekey = keys.none; Keysconverter kc = new keysconverter (); foreach (string key in keystrs) combineKey |= (Keys) KC. ConvertFromString (key. Trim ()); if (keyData == Combinekey) //do something return base. processCmdKey (ref msg, keydata); }
This article is from the "Find Problem solving" blog, so be sure to keep this source http://lafflan.blog.51cto.com/3441362/1662378
C # Custom combination shortcut key solution