Solved

C# - Create PictureBox via pure code

Posted on 2007-03-28
3
872 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 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