我在事件上动态创建和跟踪栏,现在我想要一个文本框填充跟踪栏的值。
但我怎么可能做到这一点?因为我会收到一条错误消息,说动态创建的轨迹栏不存在。这是逻辑
这就是我到目前为止所拥有的。
TrackBar trackBar = new TrackBar();
trackBar.Name = "TrackbarWidth" + trackbarName++;
trackBar.Tag = "dispose";
trackBar.Maximum = 85;
trackBar.Minimum = 65;
trackBar.SmallChange = 5;
trackBar.TickFrequency = 5;
trackBar.Value = WidthValue;
trackBar.Location = new Point(175, 440 + (50 * trackbarName));
trackBar.Size = new System.Drawing.Size(100, 25);
this.Controls.Add(trackBar);
TextBox textBox = new TextBox();
textBox.Name = "TrackbarWidth" + TextboxName++;
textBox.Text = trackBar.Value.ToString();
textBox.Tag = "dispose";
textBox.Location = new Point(300, 440 + (50 * TextboxName));
textBox.Size = new System.Drawing.Size(30, 25);
this.Controls.Add(textBox);
lineWidth += 4;
}
#endregion
}
private void trackBar1_Scroll(object sender, EventArgs e){
textBox1.Text = trackBar1.Value.ToString();
}
此解决方案的问题是我无法访问该trackBar1_Scroll
方法中的文本框或轨迹栏。