C# winform中組合鍵奇怪不響應問題


再winform中使用ProcessCmdKey處理快捷鍵響應,針對單一快捷鍵響應沒有任何問題。但是針對組合鍵總是無法響應,如下:

protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control|Keys.C ))
            {
                MessageBox.Show("Ctrl+C");
                return true;
            }
            return false;
        }

找了不少解釋,也沒找到原因。

后來在StackOverflow上看到一個人說把順序調換一下,亦即:

protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, Keys keyData)
        {
            if (keyData == (Keys.C|Keys.Control))
            {
                MessageBox.Show("Ctrl+C");
                return true;
            }
            return false;
        }

就可以正常響應。

記錄一下,希望其他人別踩坑了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM