Solved

C# - Create PictureBox via pure code

Posted on 2007-03-28
3
833 Views
Last Modified: 2010-05-18
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.

Cheers!


[EDIT]

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")));
                resources.ReleaseAllResources();
                myPic.Location = new Point(pictureBox1.Left + e.X - startX, pictureBox1.Top + e.Y - startY);
0
Comment
Question by:Cyber-Drugs
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
ksaul earned 500 total points
ID: 18812041
// Create the object and set properties
           PictureBox pc = new PictureBox();
            pc.Name = "PictureBoxX";
            pc.Left = 1;
            pc.Height = 1234;
            pc.Width = 123;
//         pc.Load(@"c:\images\blah.gif"); //Loads a new image
           pc.Iamge = PictureBox1.Image;  //mage from existing picturebox
// Add the control to your form and show it
            this.Controls.Add(pc);
            pc.Show();
0
 
LVL 10

Expert Comment

by:ksaul
ID: 18812111
typo here >  pc.Image = PictureBox1.Image;  //Image from existing picturebox
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18812219
That did the trick, cheers! :o)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now