using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 用于捕获当前界面下按键事件
/// 此方法继承自Form对象
/// 如果为回车或ESC
/// </summary>
/// <param name="msg"></param>
/// <param name="keyCode"></param>
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, Keys keyCode)
{
switch (keyCode)
{
case Keys.Escape: // ESC键
this.Close();
break;
case Keys.Enter: // 点击回车事件
MessageBox.Show("Enter");
break;
case Keys.D0:
case Keys.NumPad0:
MessageBox.Show("0");
break;
case Keys.D1:
case Keys.NumPad1:
MessageBox.Show("1");
break;
case Keys.D2:
case Keys.NumPad2:
MessageBox.Show("2");
break;
default:
return false;
}
return true;
}
}
}