三个文本框,textbox1,textbox2,textbox3,初始化时候给textbox3一个字符串,比如000000,如果现在需要在改变textbox1里文本的时候,textbox3前三个字符跟这变化,改变textbox2的时候后三位跟着变化,该怎么解决。

解决方案 »

  1.   

    textbox1的textchanged事件:
    textbox3.text = textbox1.text + textbox3.text.substring(3,6)
    textbox2的textchanged事件:
    textbox3.text = textbox3.text.substring(0,3) + textbox2.text
      

  2.   

    public Form1()
            {
                InitializeComponent();
                this.textBox3.Text = "000000";
            }        private void textBox1_TextChanged(object sender, EventArgs e)
            {
                this.textBox3.Text = this.textBox1.Text.PadLeft(3, '0') + this.textBox3.Text.Substring(3, 3);
            }        private void textBox2_TextChanged(object sender, EventArgs e)
            {
                this.textBox3.Text = this.textBox3.Text.Substring(0, 3) + this.textBox2.Text.PadRight(3, '0');
            }
      

  3.   

    一楼的问题多多,如果1,2两个textbox没有输满三位会出现什么问题。思路是对的。