-
Oct 23rd, 2012, 09:26 PM
#1
Thread Starter
New Member
Is it possible to load pictures without an openfiledialog?
Ok so i know that i can load a picture into a picturebox without an openfiledialog. What i want to do is this. Keeping it simple, I have 2 forms. on the first form, i have a picturebox, some textboxes and buttons bla bla bla. the user loads a picture (from their computer) into the picturebox, types some info into the textboxes, and clicks the button to save all text and the picture to a folder that I specify (via savefiledialog). that all works perfectly fine.
now they open the second form. the second form has a picturebox and 4 buttons. I kinda set it up like a tv lol. the first button turns on the "tv" (picturebox) on, and the second and third buttons i want to scroll through pictures without opening the dialog everytime.
Is this possible? Im trying to make it like a windows photo gallery kind of thing. with "previous" and "next" buttons where whatever picture from the folder that is displayed, when u click next it will go to the next picture in that folder. and when they get to the last picture, it will start over with the first one.
for the folder that i specify im using the following code
Code:
application.startupPath & "\logs\"
Can anyone please help me? thanks in advance!
Brian
-
Oct 23rd, 2012, 09:33 PM
#2
Re: Is it possible to load pictures without an openfiledialog?
vbnet Code:
'
'Get a list of all JPG files in the specified folder
Dim JPGFiles As String() = System.IO.Directory.GetFiles(Application.StartupPath + "\logs", "*.jpg")
The above code would get you a list of all Jpeg files in your logs folder. You already know how to use a file name to load an image so I assume you know where to go from there.
-
Oct 24th, 2012, 09:48 AM
#3
Re: Is it possible to load pictures without an openfiledialog?
If you're wanting to avoid having your program lock the image file, I would suggest you use a FileStream to read all of the bytes of the file into a Byte array, you can convert the byte array into an image object in your program anytime you want, for example, you read all of the bytes into the array, then assign a cast of that array to an image to the picturebox's image property.
Also by doing it this way, you can turn around and store the bytes in a database too.
Convert Image File to Bytes and Back - CodeProject
-
Oct 24th, 2012, 07:12 PM
#4
Thread Starter
New Member
Re: Is it possible to load pictures without an openfiledialog?
Niya, i tried to figure it out on my own but i cant im still a noob. Would I use 'count' with that? as to pull up the first file in that folder? i cant really give the file a name since the name is up to the user. im lost sorry.
-
Oct 31st, 2012, 08:28 AM
#5
Thread Starter
New Member
Re: Is it possible to load pictures without an openfiledialog?
Im still a little lost here. can anyone help?
-
Oct 31st, 2012, 09:09 AM
#6
Re: Is it possible to load pictures without an openfiledialog?
How could it be up to the user and you're not using an OpenFileDialog ?
-
Oct 31st, 2012, 04:37 PM
#7
Re: Is it possible to load pictures without an openfiledialog?
hi Glasner,
Maybe I'm understanding your question differently. I suggest you go about it like this.
1. On the first form ("Form1") define a list to hold the image file names. Make it Public so you can access it from the other form ("Form2").
Code:
Public SelectedImages As New List(Of String)
2. Each time the user saves an image to your specified folder, add the file name of the image to the list with SelectedImages.Add(filename).
3. On Form2, declare an Integer variable to track the image.
Code:
Dim imgIndex As Integer = 0
4. When the user turns on the "TV", set the picture box ("PictureBox1") to show the first image in the list:
Code:
PictureBox1.ImageLocation = Form1.SelectedImages(0)
5. Put this in the Click sub of the "Next" button:
Code:
If imgIndex < Form1.SelectedImages.Count - 1 Then
imgIndex+=1
End If
PictureBox1.ImageLocation = Form1.SelectedImages(imgIndex)
6. Put this in the "Previous" button's Click sub:
Code:
If imgIndex > 0 Then
imgIndex-=1
End If
PictureBox1.ImageLocation = Form1.SelectedImages(imgIndex)
BB
Last edited by boops boops; Oct 31st, 2012 at 04:43 PM.
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
|