获得键盘输入的按键
1 首先 KeyPreview = true;这是前提
举例子 MedicineUse是主窗体 cmbDoctor是combox2控件获得焦点
2 private void MedicineUse_KeyDown(object sender, KeyEventArgs e)
{
Keys k = e.KeyCode;
if (k == Keys.F12)
{
this.cmbDoctor.Focus();
}
}
combox2获得焦点后 Enter键等于TAB键
private void comboBox2_KeyPress_1(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
SendKeys.Send("{tab}");
}
}
SendKeys.Send("{tab}");表示向程序发送tab键
private void FrmHospital_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.F2: btnadd_Click(sender, e); break;
case Keys.F3: btnmodify_Click(sender, e); break;
case Keys.F4: btndelete_Click(sender, e); break;
}
}