Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# - Create PictureBox via pure code

Posted on 2007-03-28
3
Medium Priority
?
883 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

609 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