954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

On button click, I want the picturebox to load an image.

A THOUSAND apologies if this question has been asked time and time again.

Google gave no results and Jeeves is retired so I come looking for help in the best programming forum around.

private void button1_Click(object sender, EventArgs e)
        {
            pictureBox1.ImageLocation=???????????
        }


My question is fairly simple, what do I put at the other side of the "="?

papuccino1
Light Poster
46 posts since Aug 2008
Reputation Points: 19
Solved Threads: 1
 

either a path or a url to the image file

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

Image.FromFile(/*put your path here*/);

Jugortha
Junior Poster
172 posts since Oct 2007
Reputation Points: 11
Solved Threads: 16
 

Or you might open a filedialog in your buttonclick like this :

OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open bitmap or jpeg.";
//dlg.Filter = "jpg files (*.jpg);*.jpg;*.* | bmp files (*.bmp); *.bmp";

 if (dlg.ShowDialog() == DialogResult.OK)
 {
         this.fotoPictureBox.Image = new Bitmap(dlg.OpenFile());
 }
 dlg.Dispose();
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

Several ways to do it, here is an article on loading image files . Just make sure to dispose of new objects properly depending on how you load the images

vckicks
Junior Poster in Training
58 posts since Jun 2008
Reputation Points: 11
Solved Threads: 9
 

pictureBox1.Image = new Bitmap("D:\\2.png");

vero009
Newbie Poster
1 post since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

or if picture in resources folder then
//pictureBox1.Image = Properties.Resources.PictureName;
i.e pictureBox1.Image = Properties.Resources.img3;

hassan12345
Light Poster
42 posts since Aug 2010
Reputation Points: 10
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You