6 Replies - 565 Views - Last Post: 23 February 2012 - 08:56 AM Rate Topic: -----

#1 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,120
  • Joined: 22-February 08

Picturebox properties.

Posted 22 February 2012 - 10:13 AM

I wanted to add my own picture to the PictureBox. Basically, just wanted to play around with it. Now, a few questions.

1) At first, I tried adding in the picture using the properties window in VS, I just imported the image. And from the Designer, I see this line : [this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));]. When I see inside the resources folder, the image is .jpg? Explanation please.

2) This time, I'm doing it all manually. Say, I wanted to distribute my own picture to the user. My idea is I could just put the picture inside the same folder as the exe, and use the System.Windows.Forms.Application.StartupPath + "zzz.jpg". But how do I reflect this into the code? I tried this :
            this.pictureBox1.Location = new System.Drawing.Point(7, 4);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(265, 246);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            this.pictureBox1.ImageLocation = System.Windows.Forms.Application.StartupPath + "zzz.jpg";


And the picture is not loaded onto the PictureBox. I guess I have to use the Image property, but I don't know how should I ask the Image property to load from the path. Help please.

This post has been edited by red_4900: 22 February 2012 - 10:14 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Picturebox properties.

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9498
  • View blog
  • Posts: 35,845
  • Joined: 12-June 08

Re: Picturebox properties.

Posted 22 February 2012 - 10:26 AM

RE: #1 - the project took your image, added it to the project's resources, and referenced it.
Right click your project -> properties -> resource tab.. you should see it there.

RE: #2 - where's that code from? Are you jacking with the designer code? I would avoid that and just set the data on the form's load or new.

Have you looked at where "System.Windows.Forms.Application.StartupPath" is? Are you sure the image is in your bin's debug/release folder? Also you would need to add a few slashes between 'startuppath' and the image name.
Was This Post Helpful? 1
  • +
  • -

#3 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,120
  • Joined: 22-February 08

Re: Picturebox properties.

Posted 22 February 2012 - 10:33 AM

1) Thanks. :D

2) Yes, I'm playing around with the designer's code. My thought is, if I'm giving this to someone else, the path of the image would be different, no? So I thought I should put the image inside the same folder as the exe, load it from there. Hence, the reason why I used the 'startuppath'. I want the path of the image to be dynamic.

I tried both 1 and 2 //, it still failed. So...how?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9498
  • View blog
  • Posts: 35,845
  • Joined: 12-June 08

Re: Picturebox properties.

Posted 22 February 2012 - 12:42 PM

Quote

2) Yes, I'm playing around with the designer's code. My thought is, if I'm giving this to someone else, the path of the image would be different, no? So I thought I should put the image inside the same folder as the exe, load it from there. Hence, the reason why I used the 'startuppath'. I want the path of the image to be dynamic.

Okay - but that doesn't discount you should put a break point and see exactly where that startup path is pointing to.

Quote

I tried both 1 and 2 //, it still failed. So...how?

If you look how the startup path is creating the path string you'll see what to do and which direction the slashes should go.
Was This Post Helpful? 0
  • +
  • -

#5 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,120
  • Joined: 22-February 08

Re: Picturebox properties.

Posted 22 February 2012 - 03:50 PM

Actually that was a typo. I used \\ :P

Anyway, I already got it to work. But I'm still a bit curious. The path string points to the debug folder, so I only put it inside there (and not in release folder), I can't get the picture to load it when I run it on VS. But the picture loads when I click the exe file inside the folder. I had to put the file inside both release and debug folder to make it able to load through VS. Any idea why?

This post has been edited by red_4900: 22 February 2012 - 03:51 PM

Was This Post Helpful? 0
  • +
  • -

#6 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 182
  • View blog
  • Posts: 783
  • Joined: 27-October 11

Re: Picturebox properties.

Posted 23 February 2012 - 02:25 AM

What build are you running from VS? If you're running the debug build then it has to be in the debug folder to be properly executed, if you're running the release build then it has to be in the release folder.

You could also embed that picture in the program if you wanted, and avoid all possible complications with the image path.
Was This Post Helpful? 1
  • +
  • -

#7 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9498
  • View blog
  • Posts: 35,845
  • Joined: 12-June 08

Re: Picturebox properties.

Posted 23 February 2012 - 08:56 AM

Quote

I had to put the file inside both release and debug folder to make it able to load through VS. Any idea why?

You have two destinations for when the application is executed. If you compile and run it in debug mode Visual Studios is nice enough to make that a folder to keep separate from what you might want for release. It prevents debug crap being accidentally copied when you are ready to move your code out. It's a good thing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1