By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

How To Get Icons For Pictures Files in vb.net

P: 2
I Tried To Get Icons Of files system and display it in my list Box
But i got an empty icon For Picture Files

This Is My Code:

Expand|Select|Wrap|Line Numbers
  1.     Public Sub ExtractAssociatedIconEx()
  2.         ' Initialize the ListView, ImageList and Form.
  3.         listView1 = New ListView()
  4.         imageList1 = New ImageList()
  5.         listView1.Location = New Point(37, 12)
  6.         listView1.Size = New Size(161, 242)
  7.         listView1.SmallImageList = imageList1
  8.         listView1.View = View.SmallIcon
  9.         Me.ClientSize = New System.Drawing.Size(292, 266)
  10.         Me.Controls.Add(Me.listView1)
  11.         Me.Text = "Form1"
  12.  
  13.         ' Get the c:\ directory. 
  14.         Dim dir As New System.IO.DirectoryInfo(TextBox1.Text)
  15.  
  16.         Dim item As ListViewItem
  17.         listView1.BeginUpdate()
  18.         Dim file As System.IO.FileInfo
  19.         For Each file In dir.GetFiles()
  20.  
  21.             ' Set a default icon for the file. 
  22.             Dim iconForFile As Icon = SystemIcons.WinLogo
  23.  
  24.             item = New ListViewItem(file.Name, 1)
  25.  
  26.             ' Check to see if the image collection contains an image 
  27.             ' for this extension, using the extension as a key. 
  28.             If Not (imageList1.Images.ContainsKey(file.Extension)) Then
  29.  
  30.                 ' If not, add the image to the image list.
  31.                 iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(file.FullName)
  32.                 imageList1.Images.Add(file.Extension, iconForFile)
  33.             End If
  34.             item.ImageKey = file.Extension
  35.             listView1.Items.Add(item)
  36.  
  37.         Next file
  38.         listView1.EndUpdate()
  39.     End Sub
How I Can Get Icons For picture Files ?

Thanks
Aug 30 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.