How to check if a ctrl + enter is pressed on a control?
| // Registering against a stack event will cause memory leak, please unregister this event when you are done with it. |
| ComponentDispatcher.ThreadPreprocessMessage += ComponentDispatcher_ThreadPreprocessMessage; |
// WM_KEYDOWN 是按下一個鍵是產生的消息。
const
// WM_SYSKEYDOWN 是按下Alt鍵同時再按下別的鍵時產生的消息。
const int WM_SYSKEYDOWN = 0x0104;
void ComponentDispatcher_ThreadPreprocessMessage(ref MSG msg, ref bool handled)
{
??????if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN)
??????{
?????????// Examine if the Control and Enter keys are pressed, we also need to make sure that the?
????????// currently keyborad focused element is TextBox instance itself.?
??????? // "|" 二進制或運算,有一個為1則結果為1。
??????? // "&" 二進制與運算,兩個都為1則結果為1. Keys轉換為int的值就是Keys這個枚舉類中定義的該枚舉項的值。
?????????Keys keyData = ((Keys)((int)(msg.wParam))) | System.Windows.Forms.Control.ModifierKeys;
?????????if (((keyData & Keys.Control) == Keys.Control) &&
?????????((keyData & Keys.Enter) == Keys.Enter) &&
?????????Keyboard.FocusedElement == this.txtBox)
?????????{
???????????????System.Windows.MessageBox.Show("Ctrl+Enter is pressed");
?????????}
??????}
}
posted on 2008-08-22 16:24 cutebear 閱讀(...) 評論(...) 編輯 收藏
轉載于:https://www.cnblogs.com/bear831204/archive/2008/08/22/1273188.html
新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!總結
以上是生活随笔為你收集整理的How to check if a ctrl + enter is pressed on a control?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转]那些相见恨晚的 JavaScrip
- 下一篇: 如何绑定多个action到一个slot