我想自动创建PictureBox
。如何在代码中更改此内容:
private void button1_Click(object sender, EventArgs e)
{
PictureBox[] box = new PictureBox[textBox1.Text.Length];
for(int j=0;j<textBox1.Text.Length;j++)
box[0] = pictureBox1;
box[1] = pictureBox2;
box[2] = pictureBox3;
for (int i = 0; i < textBox1.Text.Length; ++i)
box[i].Image = Image.FromFile(string.Format(@"c:\obrazki\{0}.jpg",textBox1.Text[i]));
}
答案 0 :(得分:0)
您应该使用FlowLayoutPanel控件来保存PictureBox控件。然后代码看起来像这样:
void button1_Click(object sender, EventArgs e) {
while (flowLayoutPanel1.Controls.Count > 0) {
flowLayoutPanel1.Controls[0].Dispose();
}
for (int i = 0; i < textBox1.Text.Length; ++i) {
PictureBox pb = new PictureBox();
pb.Image = Image.FromFile(string.Format(@"c:\obrazki\{0}.jpg",textBox1.Text[i]));
flowLayoutPanel1.Controls.Add(pb);
}
}