Solved

C# - Create PictureBox via pure code

Posted on 2007-03-28
3
858 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

840 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