|
-
May 17th, 2011, 03:02 PM
#1
Thread Starter
New Member
image.fromfile query
I have been using the image.fromfile to set images to a text box but I always have to use a full file path. Like here;
Code:
PictureBox1.Image = Image.FromFile("G:\VB.NET\Application1\Resources\Image1.jpg")
PictureBox2.Image = Image.FromFile("G:\VB.NET\Application1\Resources\Image2.jpg")
However if I install the application on another computer then surely this won't work as it needs a path relative to where it is installed. I tried "\Resources\Image1.jpg" but this doesn't seem to work. I need to find away so it works on all computers. I don't know if it changes this when the application is published but I don't have access to a second computer to test it. Any one know how to do it?
-
May 17th, 2011, 03:52 PM
#2
Re: image.fromfile query
There are numerous ways, but the simple one is to use Application.StartupPath and combine it with IO.Path.Combine.
-
May 23rd, 2011, 11:05 AM
#3
Thread Starter
New Member
Re: image.fromfile query
I have tried this but it keeps bringing up an error 'FileNotFoundException was unhandled' this is my code. The file defiantly exists, as it works on my computer like above.
Code:
Dim StartPath, pic1, f1 As String
StartPath = Application.StartupPath
pic1 = "Resources\Image1.jpg"
f1 = Path.Combine(StartPath, pic1)
Main.PictureBox1.Image = Image.FromFile(f1)
Last edited by Uranium Falcoln; May 23rd, 2011 at 11:06 AM.
Reason: spelling mistake
-
May 23rd, 2011, 11:19 AM
#4
Re: image.fromfile query
Whenever you encounter "file not found" exception, always messagebox the file path to inspect it. In your case, I strongly beleive that you didn't copy the "Resources" folder to the "bin" directory of your project.
When you debug run your application, it runs from the "bin" folder of your project and thus application.startuppath returns the path to the "bin" folder.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|