直接看应用实例

/// <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();
}
}

posted on 2015-01-20 15:52  赫赫小虾  阅读(857)  评论(0编辑  收藏  举报