138 lines
4.1 KiB
C#
138 lines
4.1 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Drawing;
|
|||
|
using System.Data;
|
|||
|
using System.Text;
|
|||
|
using System.Windows.Forms;
|
|||
|
using SysFuns;
|
|||
|
|
|||
|
namespace ryControls
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 系统热键数据类。
|
|||
|
/// </summary>
|
|||
|
public partial class RyHotkey : TextBox
|
|||
|
{
|
|||
|
Keys m_Modifiers =Keys.None;
|
|||
|
Keys m_Key =Keys.None;
|
|||
|
/// <summary>
|
|||
|
/// 系统热键数据类
|
|||
|
/// </summary>
|
|||
|
public RyHotkey()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
//定义KeyPress事件
|
|||
|
//base.KeyPress += delegate(object sender, KeyPressEventArgs e) { e.Handled = true; };
|
|||
|
base.ReadOnly = true;
|
|||
|
base.BackColor = Color.White;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 使多行属性失效掉
|
|||
|
/// </summary>
|
|||
|
[Description("此属性无效")]
|
|||
|
public new bool Multiline
|
|||
|
{
|
|||
|
get{return false;}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 使只读属性失效掉
|
|||
|
/// </summary>
|
|||
|
[Description("此属性无效")]
|
|||
|
public new bool ReadOnly
|
|||
|
{
|
|||
|
get { return false; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
///获取热键文本
|
|||
|
/// </summary>
|
|||
|
[Description("此属性无效")]
|
|||
|
public new string Text
|
|||
|
{
|
|||
|
get { return base.Text; }
|
|||
|
set { }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 功能键
|
|||
|
/// </summary>
|
|||
|
[Description("功能键")]
|
|||
|
public int T_Modifiers
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
int i_Keys = 0;
|
|||
|
if ((m_Modifiers & Keys.Alt) != 0)
|
|||
|
{ i_Keys =i_Keys | 1; }
|
|||
|
if ((m_Modifiers & Keys.Control) != 0)
|
|||
|
{ i_Keys = i_Keys | 2; }
|
|||
|
if ((m_Modifiers & Keys.Shift) != 0 || (m_Modifiers & Keys.LShiftKey) != 0 || (m_Modifiers & Keys.RShiftKey) != 0)
|
|||
|
{ i_Keys = i_Keys | 4; }
|
|||
|
if ((m_Modifiers & Keys.LWin) != 0 || (m_Modifiers & Keys.RWin) != 0)
|
|||
|
{ i_Keys = i_Keys | 8; }
|
|||
|
return i_Keys;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
m_Modifiers =Keys.None;
|
|||
|
if ((value & 1) != 0)
|
|||
|
{ m_Modifiers =m_Modifiers | Keys.Alt; }
|
|||
|
if ((value & 2) != 0)
|
|||
|
{ m_Modifiers = m_Modifiers | Keys.Control; }
|
|||
|
if ((value & 4) != 0)
|
|||
|
{ m_Modifiers = m_Modifiers | Keys.Shift; }
|
|||
|
if ((value & 8) != 0)
|
|||
|
{ m_Modifiers = m_Modifiers | Keys.LWin; }
|
|||
|
HotkeyValue xvalue;
|
|||
|
xvalue = new HotkeyValue(m_Modifiers, m_Key);
|
|||
|
base.Text = xvalue.ToStr();
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 热键按键
|
|||
|
/// </summary>
|
|||
|
[Description("热键按键")]
|
|||
|
public Keys T_Key
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return m_Key;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
m_Key = value;
|
|||
|
HotkeyValue xvalue = null;
|
|||
|
xvalue = new HotkeyValue(m_Modifiers, m_Key);
|
|||
|
base.Text = xvalue.ToStr();
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected override void OnKeyDown(KeyEventArgs e)
|
|||
|
{
|
|||
|
//if (e.Modifiers == 0) //没有修改键
|
|||
|
//{
|
|||
|
// e.Handled = true;
|
|||
|
// return;
|
|||
|
//}
|
|||
|
|
|||
|
HotkeyValue value = null;
|
|||
|
if (e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.ControlKey || e.KeyCode == Keys.Menu || e.KeyCode == Keys.None)
|
|||
|
{//除修改键外,没有按键
|
|||
|
value = new HotkeyValue(e.Modifiers, Keys.None);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
value = new HotkeyValue(e.Modifiers, e.KeyCode);
|
|||
|
}
|
|||
|
m_Modifiers = value.Modifiers;
|
|||
|
m_Key = value.KeyCode;
|
|||
|
base.Text = value.ToStr();//赋值
|
|||
|
e.Handled = true;
|
|||
|
base.OnKeyDown(e);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|