当前textbox1按回车到textbox2中去,按esc退出当前窗口
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.TabIndex = 1;
textBox2.TabIndex = 2;
this.textBox1.KeyPress += new System.Windows.Forms.KeyEventHandler(this.ListKey);
this.textBox2.KeyPress += new System.Windows.Forms.KeyEventHandler(this.ListKey);
}
private void ListKey(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.SelectNextControl(this.ActiveControl, true, true, true, true);
}
if (e.KeyCode == Keys.Escape)
{
this.Close();
}
}