int num = 0; PictureBox[] pic = new PictureBox[50]; for (int i = 0; i < pic.Length; i++) { int h = num / 10; int v = num % 10; pic[i] = new PictureBox(); pic[i].Name = "PictureBox" + Convert.ToString(i + 1); pic[i].BackColor = Color.Black; pic[i].Size = new System.Drawing.Size(50, 50); pic[i].BackgroundImage = Image.FromFile("image\\"+i+".png"); pic[i].Location = new Point(h * 150 + 50, v * 150 + 50); groupBox1.Controls.Add(pic[i]); num++; }
是picturebox控件数组,方式差不多
按钮控件数组 int num = 0; Button[] bt=new Button[50]; for (int i = 0; i < bt.Length; i++) { int h = num / 10; int v = num % 10; bt[i] = new Button(); bt[i].Name = "Button" + Convert.ToString(i + 1); bt[i].BackColor = Color.Black; bt[i].Size = new System.Drawing.Size(50, 50); bt[i].Location = new Point(h * 150 + 50, v * 150 + 50); groupBox1.Controls.Add(bt[i]); num++; }
PictureBox[] pic = new PictureBox[50];
for (int i = 0; i < pic.Length; i++)
{
int h = num / 10;
int v = num % 10;
pic[i] = new PictureBox();
pic[i].Name = "PictureBox" + Convert.ToString(i + 1);
pic[i].BackColor = Color.Black;
pic[i].Size = new System.Drawing.Size(50, 50);
pic[i].BackgroundImage = Image.FromFile("image\\"+i+".png");
pic[i].Location = new Point(h * 150 + 50, v * 150 + 50);
groupBox1.Controls.Add(pic[i]);
num++;
}
Button[] bt=new Button[50];
for (int i = 0; i < bt.Length; i++)
{
int h = num / 10;
int v = num % 10;
bt[i] = new Button();
bt[i].Name = "Button" + Convert.ToString(i + 1);
bt[i].BackColor = Color.Black;
bt[i].Size = new System.Drawing.Size(50, 50);
bt[i].Location = new Point(h * 150 + 50, v * 150 + 50);
groupBox1.Controls.Add(bt[i]);
num++;
}
http://www.cnblogs.com/whtydn/archive/2009/03/19/1416498.html,