PictureBox.Image hardcoded directory?

  • Thread starter Thread starter CSharp-Jay
  • Start date Start date
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?
 
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
 
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
 
Back
Top