WinForm 实现按 Enter键 动态将光标定位到下一个TextBox

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}");中的{}
            }
        }
posted @ 2013-01-05 18:23  程序有Bug  阅读(434)  评论(0编辑  收藏  举报