zoukankan      html  css  js  c++  java
  • How to check if a ctrl + enter is pressed on a control?

    通过注册ComponentDispatcher.ThreadPreprocessMessage 事件实现。
    // 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
    int WM_KEYDOWN = 0x100;
    // 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");

             }

          }
    }


  • 相关阅读:
    C# 用this修饰符为原始类型扩展方法
    windows7命令行终端获取管理员模式随笔
    C语言---斐波那契问题
    C语言--pow()函数实现
    数组排序之选择排序
    求数组逆置(数组与指针实现)
    字符串函数之Strtok()函数
    for循环的灵活性
    C语言--isspace()函数实现
    异构无线网络之QOS简介
  • 原文地址:https://www.cnblogs.com/bear831204/p/1273188.html
Copyright © 2011-2022 走看看