PictureBox.Image hardcoded directory?

C

CSharp-Jay

Having an issue with a picturebox image. The code is supposed to find
the picture in the .\resources\ directory. I wanted to do it this way
so that the images were not all compiled as part of the executable and
to maintain the program's directory file structure. But I keep
getting "Parameter is not valid.".

this.picItem1.Image = new Bitmap(".\\resources\\iconFish.png");

Simplest thing but I cannot figure it out, anybody?
 
P

Peter Duniho

CSharp-Jay said:
Having an issue with a picturebox image. The code is supposed to find
the picture in the .\resources\ directory. I wanted to do it this way
so that the images were not all compiled as part of the executable and
to maintain the program's directory file structure. But I keep
getting "Parameter is not valid.".

this.picItem1.Image = new Bitmap(".\\resources\\iconFish.png");

Simplest thing but I cannot figure it out, anybody?

Top two likely problems:

-- the file is a format GDI+ can't handle (often a source of cryptic
error messages like "Parameter is not valid")

-- your working directory (Environment.CurrentDirectory) is not set
to the directory you think it is, and thus the relative path is invalid

Pete
 
W

wannabe geek

CSharp-Jay said:
Having an issue with a picturebox image. The code is supposed to find
the picture in the .\resources\ directory.

Are you referring to the _project_ resources directory?
I wanted to do it this way
so that the images were not all compiled as part of the executable and
to maintain the program's directory file structure. But I keep
getting "Parameter is not valid.".

this.picItem1.Image = new Bitmap(".\\resources\\iconFish.png");

Simplest thing but I cannot figure it out, anybody?
.

well, the way I see it, you have a folder/directory named "." in the same
directory as
the executable. under there, you have another named "resources". in there is
your png image.
If this is not what you have, try "..\\..\\Resources\\iconFish.png". This, i
believe, refers to _the_ resources directory in the project directory.
"..\\" refers to the parent directory of the one containing the executable.

Or, as Pete said, perhaps the CurrentDirectory is wrong.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top