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}");中的{}
            }
        }

相关文章:

  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2021-10-02
  • 2021-11-09
  • 2021-07-14
  • 2022-12-23
猜你喜欢
  • 2021-08-27
  • 2022-12-23
  • 2021-12-17
  • 2021-11-13
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
相关资源
相似解决方案