C# 键盘Enter键取代Tab键实现代码

说明:在填写表数据时当输入完一个文本框后,输入下一个文本框时需要用Tab键切换,但是有的人喜欢用Enter键切换下一个,此方法是Enter取代Tab键。

效果:

注释:键盘Enter键数字为:13

   键盘Tab键数字为:9

函数代码:

复制代码 代码如下:

private void SetEnt()

        {

            foreach (Control txt in (this.Page.Form.FindControl("ContentPlaceHolderEntity")).Controls)

            {

                if (txt is System.Web.UI.WebControls.TextBox)

                {

                    if (((TextBox)txt).CssClass != "erp_textarea")

                        ((TextBox)txt).Attributes.Add("onkeydown", "if (window.event.keyCode==13) window.event.keyCode=9");

                }

                if (txt is System.Web.UI.WebControls.DropDownList)

                {

                    ((DropDownList)txt).Attributes.Add("onkeydown", "if (window.event.keyCode==13) window.event.keyCode=9");

                }

                if (txt is System.Web.UI.WebControls.CheckBox)

                {

                    ((CheckBox)txt).Attributes.Add("onkeydown", "if (window.event.keyCode==13) window.event.keyCode=9");

                }

            }

        }

0.219944s