【发布时间】:2021-08-22 00:48:58
【问题描述】:
我的目标是将 textBox1 输入的行/行计数器获取到 textBox2 并实时显示/更新它。 到目前为止,它只有在我单击并在 textBox2 中输入内容时才有效。
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(288, 47);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(301, 193);
this.textBox1.TabIndex = 0;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(544, 265);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(45, 20);
this.textBox2.TabIndex = 1;
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
这里是 Form()
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
string strtext = textBox1.Text;
var textArr = strtext.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
textBox2.Text = textArr.Length.ToString();
}
【问题讨论】:
标签: c# visual-studio winforms