请教高手(现在没有分,有了以后献上)
有两个textbox控件:文本框textbox1和文本框textbox2,textbox1里输入完成离开时textbox2(只读)自动显示从textbox1中截取的前4个字符,代码怎样写?(现在没有分,有了以后献上)
private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode.ToString() == Keys.Enter.ToString()) { if (this.textBox1.Text.Length >= 4) { this.textBox2.Text = this.textBox1.Text.Substring(0, 4); } else { this.textBox2.Text = this.textBox1.Text; } } }
private void textBox1_Leave(object sender, EventArgs e) { if (this.textBox1.Text.Length >= 4) { this.textBox2.Text = this.textBox1.Text.Substring(0, 4); } else { this.textBox2.Text = this.textBox1.Text; } }