943,929 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 9616
  • C# RSS
Nov 1st, 2008
0

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

Expand Post »
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.

C# Syntax (Toggle Plain Text)
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. pictureBox1.ImageLocation=???????????
  4. }

My question is fairly simple, what do I put at the other side of the "="?
Similar Threads
Reputation Points: 19
Solved Threads: 1
Light Poster
papuccino1 is offline Offline
45 posts
since Aug 2008
Nov 2nd, 2008
0

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

either a path or a url to the image file
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 2nd, 2008
0

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

Image.FromFile(/*put your path here*/);
Reputation Points: 11
Solved Threads: 16
Junior Poster
Jugortha is offline Offline
172 posts
since Oct 2007
Nov 2nd, 2008
0

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

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

C# Syntax (Toggle Plain Text)
  1. OpenFileDialog dlg = new OpenFileDialog();
  2. dlg.Title = "Open bitmap or jpeg.";
  3. //dlg.Filter = "jpg files (*.jpg);*.jpg;*.* | bmp files (*.bmp); *.bmp";
  4.  
  5. if (dlg.ShowDialog() == DialogResult.OK)
  6. {
  7. this.fotoPictureBox.Image = new Bitmap(dlg.OpenFile());
  8. }
  9. dlg.Dispose();
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Nov 3rd, 2008
0

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

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
Reputation Points: 11
Solved Threads: 9
Junior Poster in Training
vckicks is offline Offline
58 posts
since Jun 2008
Oct 16th, 2010
0
Re: On button click, I want the picturebox to load an image.
pictureBox1.Image = new Bitmap("D:\\2.png");
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vero009 is offline Offline
1 posts
since Oct 2010
Oct 16th, 2010
0
Re: On button click, I want the picturebox to load an image.
or if picture in resources folder then
//pictureBox1.Image = Properties.Resources.PictureName;
i.e pictureBox1.Image = Properties.Resources.img3;
Reputation Points: 10
Solved Threads: 3
Light Poster
hassan12345 is offline Offline
42 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Emboss Effect on TextBlock
Next Thread in C# Forum Timeline: help in sql express





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC