C # Custom combination shortcut key solution

Source: Internet
Author: User

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

Related Article

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.