• 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");

             }

          }
    }


  • 相关阅读:
    iphone 图标下载
    iphone 下拉刷新(转)
    技术书评(.NET为主)
    我也设计模式——3.Singleton
    我也设计模式——14.Flyweight
    Web2.0技术研究笔记——1.分类与资源
    我也设计模式——4.Builder
    C#之CLR读书笔记 0
    IMemento 永远置顶
    我也设计模式——21.Memento
  • 原文地址:https://www.cnblogs.com/bear831204/p/1273188.html
Copyright © 2020-2023  润新知