0

ive created a new picturebox with the image to be directed from my directory.

but it came be the case that the directory path will always be on my desktop.

how do i make the path not hard-coded?

pictureBox = new PictureBox();
pictureBox.Image = Image.FromFile(@"D:\Documents and Settings\12344\Desktop\Model Products 40x40 v2\Model Products 40x40\CCTV\CCTV1Button.jpg");


this shld not be the case. it shld not be hard-coded. the directory might not be in the place where i start the program.

could someone help and tell me how to set the directory path name when i had already pasted the whole image folder into my program's directory?


thank u. appreciated.

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by Diamonddrake
Featured Replies
  • *sigh* [CODE]string path = Application.StartupPath; string subfolder = @"\Images\"; string imagefilename = "myjpeg.jpg"; pictureBox.Image = Image.FromFile(path + subfolder + imagefilename);[/CODE] Read More

0

there are quite a few ways to do this, simplest

string path =  Application.StartupPath;
//This gets the directory the application was started from.

And more complicated, but many people will tell you this is the only correct way, I argue against that. but it certainly does work also.

string correctPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

Edited by Diamonddrake: n/a

0

okay, but how do u direct to a particular jpeg in the directory ?

1

*sigh*

string path =  Application.StartupPath;
string subfolder = @"\Images\";
string imagefilename = "myjpeg.jpg";

pictureBox.Image = Image.FromFile(path + subfolder + imagefilename);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.