• [原创]Keys的基本操作总结,判断Keys中是否存在Keys.Control|Keys.Alt,移除Keys中的部分键值。


    直接看应用实例

    /// <summary>

    /// 组合键转换成字符串类型
    /// </summary>
    /// <param name="keyCode">键值</param>
    /// <returns>字符串</returns>
    private string CombineKeyCodeToString(Keys keyCode)
    {
    if (keyCode == Keys.None) return "无";

    string strResult = string.Empty;
    // 判断是否包含Ctrl键
    if ((keyCode & Keys.Control) == Keys.Control)
    {
    strResult += "Ctrl + ";
    // 去除Ctrl键
    keyCode &= ~Keys.Control;
    }
    // 判断是否包含Alt键
    if ((keyCode & Keys.Alt) == Keys.Alt)
    {
    strResult += "Alt + ";
    // 去除Alt键
    keyCode &= ~Keys.Alt;
    }

    strResult += SingleKeyCodeToString(keyCode);

    return strResult;
    }

    /// <summary>
    /// 单键转换成字符串类型
    /// </summary>
    /// <param name="KeyCode">键值</param>
    /// <returns>字符串</returns>
    private string SingleKeyCodeToString(Keys KeyCode)
    {
    if (KeyCode >= Keys.D0 && KeyCode <= Keys.D9)
    {
    return KeyCode.ToString().Remove(0, 1);
    }
    else if (KeyCode >= Keys.NumPad0 && KeyCode <= Keys.NumPad9)
    {
    return KeyCode.ToString().Replace("Pad", "");
    }
    else
    {
    return KeyCode.ToString();
    }
    }

  • 相关阅读:
    Bugly和dispatch_once Crash
    IQKeyboardManager
    Storyboard References
    Book
    Git管理
    iOS开发之RunLoop--转
    H264之PPS、SPS了解
    iOS之UI设置随记
    使用 github 本地项目上传到github上 步骤
    spring中自定义注解
  • 原文地址:https://www.cnblogs.com/hehexiaoxia/p/4236313.html
Copyright © 2020-2023  润新知