Visual C# 2008 Adding Picture Boxes Dynamically

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Manifest222
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 9
Joined: Tue Jan 26, 2010 10:17 pm

Visual C# 2008 Adding Picture Boxes Dynamically

Post by Manifest222 »

So to add a picture box dynamically to the stage, it's very simple.

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);
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.
Post Reply