I have created:
private System.Windows.Forms.PictureBox [] RedBoxes;
Then in form_load, I do:
RedBoxes = new PictureBox[20];
for (int i = 0; i < 20; i++)
{
RedBoxes[i] = new PictureBox();
RedBoxes[i].Image = global::IDMTestClient.Properties.Resources.Red;
RedBoxes[i].Name = "RedBox" + i.ToString();
RedBoxes[i].Size = new Size(1, 38);
RedBoxes[i].Location = new Point(i + 10, 32);
RedBoxes[i].TabIndex = i + 2;
RedBoxes[i].TabStop = false;
groupBox3.Controls.Add(RedBoxes[i]);
RedBoxes[i].Visible = false;
RedBoxes[i].BringToFront();
}
Now when I try to access RedBoxes in another function, it throws an:
"A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll"
eg:
when I do:
RedBoxes[i].Left = 10;
or
RedBoxes[i].Location = new Point(10, 32);
What am I doing wrong?
/------------------UPDATE-------------------/
base {System.SystemException} = {"Cross-thread operation not valid: Control 'groupBox3' accessed from a thread other than the thread it was created on."}
This is what RedBoxes[i] has. The work of the WinForms auto generated threads?