I have a class in which I dynamically create a picturebox and atrribute an image to it. Then i want to have it added to my form, but I can't use the this pointer, instead i declared an instance of the form class in which I want to add the picturebox, but I keep getting an error runtime called 'System.StackOverflowException'. Can someone please help.
public class ElectricalComponent
{
Form1 hello = new Form1();
public void Instance(Point p)
{
PictureBox Temp = new PictureBox();
string path = @"C:\AG00103.GIF";
Temp.Location = new Point(p.X, p.Y);
Temp.Size = new Size (100, 100);
Temp.SizeMode = PictureBoxSizeMode.StretchImage;
Temp.Image = Image.FromFile (path);
hello.Controls.Add(Temp);
}
}