-
Apr 10th, 2017, 05:14 PM
#1
Thread Starter
Lively Member
Problem sending a pic to a picturebox.
I have a folder of JPG mages located in the same folder where the SLN file is.
How do I use code to display said pictures pictureboxs?
Can I establish the path to said folder? It doesn't have to be in that location. It just has to have easy access.
Last edited by GarySut; Apr 10th, 2017 at 05:16 PM.
Reason: clarity
-
Apr 10th, 2017, 05:34 PM
#2
Hyperactive Member
Re: Problem sending a pic to a picturebox.
Well if you just trying to get a few images into picture boxes then you could do something like this. The CurDir() will provide the folder that your program is being run from.
vb.net Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click PictureBox1.ImageLocation = CurDir() & "\" & "FileName.jpg" End Sub
If you wanted to display all the images in the folder similar to how they look within the folder you can add a view like that using a ListView.
-
Apr 10th, 2017, 06:06 PM
#3
Thread Starter
Lively Member
Re: Problem sending a pic to a picturebox.
Originally Posted by Vexslasher
Well if you just trying to get a few images into picture boxes then you could do something like this. The CurDir() will provide the folder that your program is being run from.
vb.net Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PictureBox1.ImageLocation = CurDir() & "\" & "FileName.jpg"
End Sub
If you wanted to display all the images in the folder similar to how they look within the folder you can add a view like that using a ListView.
I just knew it would be an easy reply. I forgot about CurDir().
I made the mistake of asking in another forum and I received all sorts of complexity such as timers and VB settings along with about 15 lines of code...
Thanks, I will check it out.
-
Apr 10th, 2017, 06:10 PM
#4
Re: Problem sending a pic to a picturebox.
Of course if your pictures are in your .sln directory, that would usually be three directories up from the executable.
Assuming Vexslasher's code is correct...
Code:
PictureBox1.ImageLocation = CurDir() & "\..\..\..\" & "FileName.jpg"
Also assumes you don't start the program from another program or batch file, which may make the curdir where the batch file or launching program is, not where the executable you're running resides.
If you use Application.ExecutablePath instead of CurDir, that will return where the executable is, not what the curdir happens to be.
Last edited by passel; Apr 10th, 2017 at 06:14 PM.
-
Apr 10th, 2017, 06:17 PM
#5
Re: Problem sending a pic to a picturebox.
I'd suggest that, as a longer term solution, you look into the Windows special folders:
https://msdn.microsoft.com/en-us/lib...v=vs.100).aspx
The reason for doing this is just that, as passel suggests, things move about. During development, the program will be in one place, after deployment (if this is a program that will actually be deployed), then it will be somewhere else. CurDir is convenient because it gives you "this here directory!", and that's what the special folders do, as well, except that "this here directory" depends on where the application is running from, which can change. By using the special folders, you have something that is more wordy than CurDir, but does effectively the same thing, and it won't be moving around on you. Of course, if this is just for testing, or single use, and will never be deployed, this doesn't matter.
My usual boring signature: Nothing
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
|