用C#如何实现如下功能?
在页面上插入三个TextBox控件,只能往每个TextBox中录入0-9中的1位数。如果在TextBox1中录入了一位数,光标就自动跳到TextBox2中,准备录入下一个数。如何实现?

解决方案 »

  1.   

    想把textBox的MaxLength的值设置为1
    然后调用 textBox1_TextChanged方法:
    具体如下:
    private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
    this.textBox2.Focus ();
    }
    private void textBox2_TextChanged(object sender, System.EventArgs e)
    {
    this.textBox3.Focus ();
    }
    不知道这样能不能达到你的要求!
      

  2.   

    What's U mean?
    能把HTML代码贴出来吗?
      

  3.   

    用 javaScript ,不过 javascript用多了不好维护和测试,而且有时会不稳定喔,慎用!
    其实可以让用户在一个TextBox中输入3个数字,再用验证控件验证。
      

  4.   

    <%@ Page language="c#" Codebehind="test.aspx.cs" AutoEventWireup="false" Inherits="Web.test" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <html>
      <head>
        <title>test</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name=vs_defaultClientScript content="JavaScript">
        <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
        <script language=javascript>
    <!--
    function jump(index)
    {
    //alert(document.all.txtOne.value.charAt(0));
    if(index==1)
    {
    if(document.all.txtOne.value.charAt(0)>="1"||document.all.txtOne.value.charAt(0)<="9")
    {
    document.all.txtTwo.focus();
    }
    }
    else if(index==2)
    {
    if(document.all.txtTwo.value.charAt(0)>="1"||document.all.txtTwo.value.charAt(0)<="9")
    {
    document.all.txtThree.focus();
    }
    }
    }
    //-->
    </script>
      </head>
      <body>
        <form id="Form1" method="post" runat="server">
    <input type="text" name="txtOne" id="txtOne" Runat="server" onkeyup="jump(1)">
    <input type="text" ID="txtTwo" Runat="server"  name="txtTwo" onkeyup="jump(2)">
    <input type="text" ID="txtThree" Runat="server" MaxLength=1 name="txtThree">
         </form>
      </body>
    </html>
      

  5.   

    <input runat="server" onkeyup="return T1_onkeyup()" id="t1" type="text"> <input onkeyup="return T2_onkeyup()" runat="server" id="t2" type="text" NAME="Text1">
    <input runat="server" id="t3" type="text" NAME="Text2">
    <script language="javascript">
    function T1_onkeyup() 
         {
                 if(document.Form1.t1.value.length==1)
                    {
                      if(event.keyCode>=48&&event.keyCode<=57)
                          {
                            document.Form1.t2.focus();
                          }
                        
                     }
        }
    function T2_onkeyup() 
         {
                 if(document.Form1.t2.value.length==1){
                      if(event.keyCode>=48&&event.keyCode<=57)
                          {
                            document.Form1.t3.focus();
                         }
                        
       }
    } </script>
      

  6.   

    48是0的ASCII码,57是9的。在keyup事件中,我用了,可以实现。
      

  7.   

    bool a;
    private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
    if(!a){
    textBox1.Text ="";
    }
    a=false;
    } private void textBox1_KeyPress(object er,                              System.Windows.Forms.KeyPressEventArgs e)
    {
    if(e.KeyChar >= 48 && e.KeyChar <=57)
    {
    textBox2.Focus ();
    a=true;
    }

    }