Hey guys is there a way to make a gallery that loads a directory automaticly?like no browse.
lets say opens folder/images1
and list all images(pictures not names)
Printable View
Hey guys is there a way to make a gallery that loads a directory automaticly?like no browse.
lets say opens folder/images1
and list all images(pictures not names)
The code to load the images would be same whether there's browsing or not. The browsing part would just be displaying an FolderBrowserDialog to allow the user to select the path. Once you've got the path, wherever it came from, loading the images is exactly the same: you call Directory.GetFiles to get a list of all the image files in a folder, then you call Image.FromFile on each one to create an Image object.
ok so just a stupid question that is killing me..
lets say this is my page
when you have a function like thatCode:Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fInfo As FileInfo()
Dim x As Integer = 0
Dim dirInfo As DirectoryInfo = New DirectoryInfo("C:\Users\TECHKER\Pictures\MISC")
fInfo = dirInfo.GetFiles("*.jpg")
Dim files As String()
Dim File As String
files = Directory.GetFiles("C:\Users\TECHKER\Pictures\MISC", "*.jpg")
For Each File In files
'Use your code that you provided
'above to read the files' text.
x += 1
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
End Class
were do you put it?and how do you make it that when you press it shows the content?
I'm not quite sure what you're asking because you've already placed the code in the Click event handler of Button1 on Form1, so it's already going to be executed when you click that button. The problem is, you aren't creating any Image objects from the files. As I said in my previous post, you need to call Image.FromFile to create an Image object from a file path. You can then do whatever's appropriate with that Image object, e.g. add it to a List(Of Image).
well thats my problem. i know were to put the code but when you press how to you make it so it can list in listbox1..
cause now there is now indication
List what? No indication of what? You need to be clear because we can't tell what you're thinking. You need to specify EXACTLY what you expect to happen. Are you saying that you want the Images to appear in the ListBox? If so then you'll be disappointed because, without some serious customisation, a ListBox won't display Images. You'd need a ListView or some custom combination of your own involving PictureBoxes.
thats it a list view.so my question is :
were do you put the code.
button1
now if i put a list view box on my for how do i link the button to it?how does the button know where to output the information?Code:Dim fInfo As FileInfo()
Dim x As Integer = 0
Dim dirInfo As DirectoryInfo = New DirectoryInfo("C:\Users\TECHKER\Pictures\MISC")
fInfo = dirInfo.GetFiles("*.jpg")
Dim files As String()
Dim File As String
files = Directory.GetFiles("C:\Users\TECHKER\Pictures\MISC", "*.jpg")
For Each File In files
'Use your code that you provided
'above to read the files' text.
x += 1
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
You don't link a ListView to a Button. Think about what you're trying to do. You're trying to load Images into a ListView when a Button is clicked. As such, whatever code you write must go in the Click event handler of the Button. You've already got that, so you're on the right track. Now you've just got to put the CORRECT code there. You already know, from my previous posts, that you need to call Image.FromFile to create an Image object for each file path. Where do you suppose that should go? Read what I posted:Now read your code:Quote:
you need to call Image.FromFile to create an Image object for each file path
Next, you know that you need to use a ListView. That means you need to do some reading on ListViews to see how they work and how you can load Images into one.Quote:
For Each File In files
sorry it's because im very visual!lol need to see it to understand..
i will study this.thx.
only because I'm bored at the moment:
vb.net Code:
Private IL As New ImageList Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListView1.View = View.LargeIcon ListView1.LargeImageList = Me.IL IL.ImageSize = New Size(128, 80) ' widescreen format 1.6 aspect ratio (adjust to your liking) | max 256x256 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ListView1.Items.Clear() IL.Images.Clear() Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) For Each file As String In My.Computer.FileSystem.GetFiles(path, FileIO.SearchOption.SearchTopLevelOnly, New String() {"*bmp", "*.jpg", "*.png", "*.gif"}) Dim thumb As Bitmap = GetThumbNail(file) If Not IsNothing(thumb) Then IL.Images.Add(thumb) Dim lvi As ListViewItem = ListView1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file), IL.Images.Count - 1) lvi.Tag = file ' store the full path to the image for later use End If Next End Sub Private Function GetThumbNail(ByVal ImageFileName As String) As Bitmap Static PB As New PictureBox PB.Size = IL.ImageSize PB.SizeMode = PictureBoxSizeMode.Zoom Try Dim bmp As New Bitmap(IL.ImageSize.Width, IL.ImageSize.Height) Using fs As New System.IO.FileStream(ImageFileName, IO.FileMode.Open) PB.Image = Image.FromStream(fs) PB.DrawToBitmap(bmp, PB.ClientRectangle) End Using Return bmp Catch ex As Exception MessageBox.Show(ex.Message & vbCrLf & "File: " & ImageFileName, "Error Loading Image", MessageBoxButtons.OK, MessageBoxIcon.Error) Return Nothing End Try End Function Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick Dim pt As Point = ListView1.PointToClient(Cursor.Position) Dim lvi As ListViewItem = ListView1.GetItemAt(pt.X, pt.Y) If Not IsNothing(lvi) Then Process.Start(lvi.Tag) End If End Sub
1. You won't learn a thing by just copy and pasting that code
2. It is not my code, but it works
3. Spell check is your friend
thx dude!
so this is the full page
Can i change the directory?Code:Imports System.IO
Public Class Form3
Private IL As New ImageList
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListView1.View = View.LargeIcon
ListView1.LargeImageList = Me.IL
IL.ImageSize = New Size(128, 80) ' widescreen format 1.6 aspect ratio (adjust to your liking) | max 256x256
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListView1.Items.Clear()
IL.Images.Clear()
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
For Each file As String In My.Computer.FileSystem.GetFiles(path, FileIO.SearchOption.SearchTopLevelOnly, New String() {"*bmp", "*.jpg", "*.png", "*.gif"})
Dim thumb As Bitmap = GetThumbNail(file)
If Not IsNothing(thumb) Then
IL.Images.Add(thumb)
Dim lvi As ListViewItem = ListView1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file), IL.Images.Count - 1)
lvi.Tag = file ' store the full path to the image for later use
End If
Next
End Sub
Private Function GetThumbNail(ByVal ImageFileName As String) As Bitmap
Static PB As New PictureBox
PB.Size = IL.ImageSize
PB.SizeMode = PictureBoxSizeMode.Zoom
Try
Dim bmp As New Bitmap(IL.ImageSize.Width, IL.ImageSize.Height)
Using fs As New System.IO.FileStream(ImageFileName, IO.FileMode.Open)
PB.Image = Image.FromStream(fs)
PB.DrawToBitmap(bmp, PB.ClientRectangle)
End Using
Return bmp
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & "File: " & ImageFileName, "Error Loading Image", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return Nothing
End Try
End Function
Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
Dim pt As Point = ListView1.PointToClient(Cursor.Position)
Dim lvi As ListViewItem = ListView1.GetItemAt(pt.X, pt.Y)
If Not IsNothing(lvi) Then
Process.Start(lvi.Tag)
End If
End Sub
End Class
i just downloaded a book..going to start big time..
Wrox.Visual.Basic.2008.Programmers.Reference.Feb.2008
really appreciate the help.
sure you can. the line:
vb Code:
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
is where you set the path of the folder that contains your images
so i have tried changing the path with
how can i set it to my project folders..Code:Dim path As String = Environment.GetFolderPath("c:/....")
or
Dim path As String = Environment.GetFolderPath(My.Application.Info.DirectoryPath & "shoulder/dum-01.bmp")
no success error messages..
Have you read the documentation for the Environment.GetFolderPath method? That will tell you how it should be used.
If you want to get the path of your program folder then you've already got it. That's exactly what My.Application.Info.DirectoryPath is.
i did but i cant seem to pin point it..
cause My.Application.Info.DirectoryPath gives me an integer error..
cause the way it is set up that is the only way it will work..cause when i read up directory path i need to change the code..string to integer
Application data : C:\Documents and Settings\LeeT\Application Data
Commom Application data : C:\Documents and Settings\All Users\Application Data
Common Program files : C:\Program Files\Common Files
Cookies : C:\Documents and Settings\LeeT\Cookies
Desktop : C:\Documents and Settings\LeeT\Desktop
Desktop Directory : C:\Documents and Settings\LeeT\Desktop
Favorites : C:\Documents and Settings\LeeT\Favorites
History path : C:\Documents and Settings\LeeT\Local Settings\History
Internet Cache : C:\Documents and Settings\LeeT\Local Settings\Temporary Internet Files
My Computer :
My Documents : C:\Documents and Settings\LeeT\My Documents
My Music : C:\Documents and Settings\LeeT\My Documents\My Music
My Pictures : C:\Documents and Settings\LeeT\My Documents\My Pictures
Personal : C:\Documents and Settings\LeeT\My Documents
Recent : C:\Documents and Settings\LeeT\Recent
SendTo : C:\Documents and Settings\LeeT\SendTo
Start Menu : C:\Documents and Settings\LeeT\Start Menu
System path : C:\WINDOWS\system32
Templates : C:\Documents and Settings\LeeT\Templates
tried this to
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\shoulder"
You misunderstand me. You do NOT need Environment.GetFolderPath at all. My.Application.Info.DirectoryPath IS the path.
So tlike this.
i gues cause i was using 2 path's..
Dim path As String = My.Application.Info.DirectoryPath & "shoulder/dum-01.bmp"