private void Form2_Load(object sender, EventArgs e) { foreach (Control c in this.Controls) //获取页面中的所有控件 { if (c.GetType().ToString() == "System.Windows.Forms.TextBox")//如果是TextBox控件,则添加事件 { TextBox tb1=c as TextBox; c.KeyDown += new KeyEventHandler(Key_Down); } } } private void Key_Down(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { //this.SelectNextControl(this.ActiveControl,true, true, true, true); SendKeys.Send("{Tab}"); //向活动应用程序发送击键 注意格式:Send("{Tab}");中的{} } }
|
|