RT,理解不了可以问我
另外怎么限制一个文本框的输入上限,就是点击数字键输入内容达到上限后不能继续输入,或是输入到一定位数自动转换到另一个文本框
新手,麻烦说的通俗点

解决方案 »

  1.   

    请留意文本框的 MaxLength 属性..
     textBox1.MaxLength = 5;
      

  2.   

    或是输入到一定位数自动转换到另一个文本框;
    //如果是纯数字.
    //字符长度超过10.
                if (textBox1.TextLength > 10)
                {
                    //文本框2获取焦点.
                    textBox2.Focus();
                }
      

  3.   


    ...WinForm  or  ..?MaxLength的确是限制文本输入长度的属性..尝试直接F4从属性设置.
      

  4.   

            //TextChange事件
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                if (textBox1.TextLength > 10)
                {
                    textBox2.Focus();
                }
            }
      

  5.   

        尝试检查代码中, 在你选中新的textBox2之后,     是否有事件触发, 重新使你的textBox1获取焦点.
      

  6.   

    模拟了一个简单的. 界面有2个文本框 ,1和2.
    public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();            textBox1.Focus();   //初始化,文本框1获取焦点
            }        private void textBox1_TextChanged(object sender, EventArgs e)
            {
                //如果文本框1的长度大于10,则文本框2获取焦点
                if (textBox1.TextLength > 10)
                {
                    textBox2.Focus();
                }
            }
        }
      

  7.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    namespace WindowsFormsApplication4
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                CenterToScreen();
            }
            private void plus_Click_1(object sender, EventArgs e)
            {
                
                no1.Focus();
                result.Clear();
                result.Text = "";
                long n1, n2, n3;
                n1 = long.Parse(no1.Text);
                n2 = long.Parse(no2.Text);
                n3 = n1 + n2;
                result.Text += ("" + n3 + "");
            }        private void minus_Click(object sender, EventArgs e)
            {
                no1.Focus();
                result.Clear();
                result.Text = "";
                long n1, n2, n3;
                n1 = long.Parse(no1.Text);
                n2 = long.Parse(no2.Text);
                n3 = n1 - n2;
                result.Text += ("" + n3 + "");
            }        private void cheng_Click(object sender, EventArgs e)
            {
                no1.Focus();
                result.Clear();
                result.Text = "";
                long n1, n2, n3;
                n1 = long.Parse(no1.Text);
                n2 = long.Parse(no2.Text);
                n3 = n1 * n2;
                result.Text += ("" + n3 + "");
            }        private void chu_Click(object sender, EventArgs e)
            {
                no1.Focus();
                result.Clear();
                result.Text = "";
                long n1, n2, n3;
                n1 = long.Parse(no1.Text);
                n2 = long.Parse(no2.Text);
                if (n2 != 0)
                {
                    n3 = n1 / n2;
                    result.Text += ("" + n3 + "");
                }
                else
                {
                    MessageBox.Show("错误!");
                }
            }        private void button1_Click(object sender, EventArgs e)
            {
                this.no1.Text = this.no1.Text + 7;
            }        private void bt8_Click(object sender, EventArgs e)
            {
                this.no1.Text = this.no1.Text + 8;
            }        private void bt9_Click(object sender, EventArgs e)
            {
                this.no1.Text = this.no1.Text + 9;
            }        private void bt4_Click(object sender, EventArgs e)
            {
                this.no1.Text = this.no1.Text + 4;
            }        private void bt5_Click(object sender, EventArgs e)
            {
                this.no1.Text = this.no1.Text + 5;
            }        private void bt6_Click(object sender, EventArgs e)
            {
                this.no1.Text = this.no1.Text + 6;
            }        private void bt1_Click(object sender, EventArgs e)
            {
                this.no1.Text = this.no1.Text + 1;
            }        private void bt2_Click(object sender, EventArgs e)
            {
                this.no1.Text = this.no1.Text + 2;
            }        private void bt3_Click(object sender, EventArgs e)
            {
                this.no1.Text = this.no1.Text + 3;
            }        private void no1_TextChanged(object sender, EventArgs e)
            {
            
                    no1.MaxLength = 10;
               
                if (no1.TextLength >= 10)
                {
                    
                    no2.Focus();
                }
                        }        private void button1_Click_1(object sender, EventArgs e)
            {
                no1.Clear();
                no1.Focus();
                no2.Clear();
                result.Text = "";
            }        private void no2_TextChanged(object sender, EventArgs e)
            {
                no2.MaxLength = 10;
            }    
                }
    }
      

  8.   

    另外就是怎么禁止输入数字以外的任何字符?
    e.Handle那个我这里实现不了
      

  9.   


    public bool isInt(string str)
            {
                //^([+-]?)表示加减号只能出现在字符串开头且只有一位
                ///d*表示后面可以有多个或一个十进制数
                //$表示字符串结尾
                return Regex.IsMatch(str, @"^([+-]?)/d*$");//返回只能以正负号开头的整数
            }再TextChanged事件,写你的处理办法
      

  10.   

    建议你的命名规范一下..  尝试检查所有 Focus();
      打上断点, 看看为什么textbox1 一直处于Focus 状态.  //button1_click  是什么事件?
      private void button1_Click_1(object sender, EventArgs e)
      {
      no1.Clear();
      no1.Focus();    //no1获取焦点
      no2.Clear();
      result.Text = "";
      }
      

  11.   

    不不不。。textbox1达到10个字符后会自动跳转到textbox2
    但是按数字按钮还是往1输入内容,用键盘的话才向2输入
    button1是清空按钮
    命名我看起来方便就这样来了
      

  12.   

    额..懂你的意思了.....自己做了9个Button当数字键..你每次点Button 的时候..焦点已经失去了..仔细看一下你这个事件.
    private void button1_Click(object sender, EventArgs e)
            {
                this.no1.Text = this.no1.Text + 7;  //只是给no1 这个文本框累加值.
            }建议你定义一个全局变量, 用来记载textbox 1 和 textbox 2 的焦点状况.
      

  13.   


            //仅供参考.
            string focus = string.Empty;    //记录了当前该由哪个文本框获取内容.
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                if (textBox1.TextLength > 10)
                {
                    textBox2.Focus();
                    focus = "textBox2";
                }
            }        //数字1 的按钮事件.
            private void button1_Click(object sender, EventArgs e)
            {
                if (focus.Equals("textBox2"))
                {
                    textBox2.Text += "1";
                }
                else
                {
                    textBox1.Text += "1";
                }
            }