-4
     PictureBox[] p = new PictureBox[15];
        for (int i = 0; i == 15; i++)
        {
            p[i] = new PictureBox();
            p[i].Name = "ItemNum" + i.ToString();
            p[i].Location = new Point(0, 0);
            p[i].Size = new Size(10, 10);
            p[i].Visible = true;
            p[i].BackColor = Color.Red;
            this.Controls.Add(p[i]);


        }

i couldnt make Location.How should i write?How can i enhance the top and lef of the location for each picturebox

2 Answers2

1
for (int i = 0; i < 16; i++)
{
    PictureBox p = new PictureBox();
    p.Location = new Point(10, (i + 1) * 20);
    p.Size = new Size(10, 10);
    p.BorderStyle = BorderStyle.FixedSingle;
    groupBox1.Controls.Add(p);
}

Use the above code after

InitializeComponent();

in your Form constructor.

Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
neutrino2039
  • 126
  • 10
0

A few issues here

  • Create the picture box inside of the for loop
  • the for loop is wrong, it never runs. The 2nd expression determines when the for loops ends.
  • Your need to add the new picture to the form/groupBox1
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73