Visual C# 2008 Adding Picture Boxes Dynamically
Posted: Sat Jan 30, 2010 11:58 pm
So to add a picture box dynamically to the stage, it's very simple.
Here is some code that I would use:
1: We add a new variable that links up with the PictureBox() class.
2: We set a location for our new myPicBox.
3: We set the width of our myPicBox.
4: We set the height of our myPicBox.
5: The Visible setting in our myPicBox is set to true allow us to see our myPicBox.
6: We set an image to our myPicBox so we can see the content we want to see.
7: We add our myPicBox to the screen.
I hope this helped you guys out. Peace.
Here is some code that I would use:
Code: Select all
PictureBox myPicBox = new PictureBox();
myPicBox.Location = new Point(0, 0);
myPicBox.Width = 100;
myPicBox.Height = 50;
myPicBox.Visible = true;
myPicBox.Image = new Bitmap(image here);
this.Controls.Add(myPicBox);
2: We set a location for our new myPicBox.
3: We set the width of our myPicBox.
4: We set the height of our myPicBox.
5: The Visible setting in our myPicBox is set to true allow us to see our myPicBox.
6: We set an image to our myPicBox so we can see the content we want to see.
7: We add our myPicBox to the screen.
I hope this helped you guys out. Peace.