C# - Create PictureBox via pure code
Posted on 2007-03-28
Hey guys 'n gals,
Could somebody enlighten me in how I could create a new PictureBox with pure code, please? I want to basically have the ability to create/destroy multiple picture boxes on my Form via code, rather than having to physically drag and drop them onto the Form.
Sorry, forgot to also mention, I want to change the Picture inside the newly created PictureBox to be the Picture which is inside an existing PictureBox. So far I have tried this, but it doesn't quite work...
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
myPic.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
myPic.Location = new Point(pictureBox1.Left + e.X - startX, pictureBox1.Top + e.Y - startY);