|
-
Jan 19th, 2010, 07:13 AM
#1
Thread Starter
Member
open directory
hey guys im trying to open a directory to list the images in it ..i have this up to know
Code:
Dim strFileSize As String = ""
Dim di As New IO.DirectoryInfo("C:\Users\TECHKER\Pictures")
Dim aryFi As IO.FileInfo() = di.GetFiles("*.*")
Dim fi As IO.FileInfo
For Each fi In aryFi
If fi.Extension = ".jpg" Or fi.Extension = ".gif" Or fi.Extension = ".bmp" Then ''etc etc etc
strFileSize = (Math.Round(fi.Length / 1024)).ToString()
Console.WriteLine("File Name: {0}", fi.Name)
Console.WriteLine("File Full Name: {0}", fi.FullName)
Console.WriteLine("File Size (KB): {0}", strFileSize)
Console.WriteLine("File Extension: {0}", fi.Extension)
Console.WriteLine("Last Accessed: {0}", fi.LastAccessTime)
Console.WriteLine("Read Only: {0}", (IO.FileAttributes.ReadOnly = True).ToString)
End If
Next
-
Jan 19th, 2010, 07:34 AM
#2
Re: open directory
I used a listbox rather than writing it to the console, but other than that, I used the code you have and didn't experience any problems.
You told us what you were trying to do, and what you were trying to do it with. What you haven't told us is what happens when you make the try. What isn't working?
-
Jan 19th, 2010, 07:44 AM
#3
Thread Starter
Member
Re: open directory
list box is a good idea but would it show images in a given directory?that is what i need..this code does nothing..
-
Jan 19th, 2010, 08:04 AM
#4
Re: open directory
If you need to display the associated icons then:
Easy way:
vb.net Code:
dim i As Icon = Icon.ExtractAssociatedIcon("filename")
Hard (but True) way:
Google for 'system imagelist'
If you want to display the images then you won't be able to do that in console window.
You'd need to create a form and display it there.
An image is loaded from file using this code:
vb Code:
Dim img As Image = Image.FromFile("filename.jpg")
The obtained image is displayed in the paint event handler like this:
vb.net Code:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawImage(img) End Sub
-
Jan 19th, 2010, 08:09 AM
#5
Thread Starter
Member
Re: open directory
i will google system imagelist and keep you posted.thx for guiding me .
-
Jan 19th, 2010, 08:34 AM
#6
Thread Starter
Member
Re: open directory
ok so i got some thing here.
Code:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim Allfiles As String() = IO.Directory.GetFiles("C:\Users\TECHKER\Desktop\PROGRAMMING\PROJECTS\trainersTool\trainersTool\Images")
Dim strfile As String
For Each strfile In Allfiles
Dim filename As New IO.FileInfo(strfile) '/// this will give you the file name etc...
ListBox1.Items.Add(filename.Name)
Next
End Sub
but it doesn't show anything..
-
Jan 19th, 2010, 08:39 AM
#7
Re: open directory
It WON'T draw images for you. You should tell with your code how and where to draw them.
Your code simply adds file names into a Listbox, that's all. You have to code where and how do you want your images to be drawn.
As I already said, if you want ICONS then use ExtractAssociatedIcon method to extract icons and then turn on the OwnerDraw property and draw each listbox element yourself.
If you want to draw actual images (jpgs, etc) you will have to LOAD these images from disk into an IMAGE object and then DRAW them somewhere.
-
Jan 19th, 2010, 08:42 AM
#8
Re: open directory
You realise you have got this code in the SelectedIndexChanged event handler right? So that code will only be executed when you select an item in the listbox, which if you have no items in it in the first place, is impossible to do.
cicatrix - I dont think he wants to draw them, just display the file names in a listbox.
-
Jan 19th, 2010, 08:43 AM
#9
Thread Starter
Member
Re: open directory
lost..sorry
but even the file name does not show..
so need to google:
ExtractAssociatedIcon method
OwnerDraw property
-
Jan 19th, 2010, 08:44 AM
#10
Thread Starter
Member
Re: open directory
 Originally Posted by chris128
You realise you have got this code in the SelectedIndexChanged event handler right? So that code will only be executed when you select an item in the listbox, which if you have no items in it in the first place, is impossible to do.
cicatrix - I dont think he wants to draw them, just display the file names in a listbox.
i would like both
so were do i put the code?
-
Jan 19th, 2010, 08:55 AM
#11
Re: open directory
Hang it on a button_click.
Then change the OwnerDraw property to your listbox
Then change the DrawMode of your listbox to OwnerDrawVariable (or OwnerDrawFixed), depending on the size of an item you want to display be fixed or variable.
Then handle the DrawItem event of the Listbox.
Now, the most important part - read at least something about GDI+ or you'll be asking questions forever.
Use e.Graphics object to get access to drawing methods.
Look my earlier posts for information about how to load an image from file (or extract associated icon) and how to draw it using the graphics object.
-
Jan 19th, 2010, 08:57 AM
#12
Thread Starter
Member
Re: open directory
is there any examples of this?im very visual..
-
Jan 19th, 2010, 09:07 AM
#13
-
Jan 19th, 2010, 09:12 AM
#14
Thread Starter
Member
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
|