我想用trakbar创建一个矩阵。水平在增加时创建新列,反之亦然。类似地,当垂直增加时,它会增加行,当滚动值减小时,它必须减少行。
我正在使用flowlayout。
private void trackBar1_Scroll(object sender, EventArgs e)
{
foreach (TextBox tb in flowLayoutPanel1.Controls.OfType<TextBox>().ToList())
{
tb.Dispose();
flowLayoutPanel1.Width -= 100;
}
for (int i = 0; i < trackBar1.Value; i++)
{
TextBox _text = new TextBox();
_text.Name = "txt"+i;
_text.Height = 20;
_text.Width = 100;
_text.Text = _text.Name;
flowLayoutPanel1.Controls.Add(_text);
flowLayoutPanel1.Width += 100;
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 4; i++)
{
flowLayoutPanel1.Controls.Add(new TextBox { Text = "txt01", Width = 80, Height = 30 });
flowLayoutPanel1.Controls.Add(new TextBox { Text = "txt01", Width = 80, Height = 30 });
flowLayoutPanel1.Width += 100;
}
}
int scrollValue = 0;
private void trackBar2_Scroll(object sender, EventArgs e)
{
if (scrollValue < trackBar2.Value)
{
for (int i = 0; i < trackBar1.Value; i++)
{
TextBox _text = new TextBox();
_text.Name = "txt" + i;
_text.Height = 20;
_text.Width = 100;
_text.Text = _text.Name;
flowLayoutPanel1.Controls.Add(_text);
}
scrollValue = trackBar2.Value;
}
else
flowLayoutPanel1.Height -= 30;
}