如何在vb.net中获取图片文件的图标
我试图获取文件系统的图标并将其显示在我的列表框中 但我有一个空的图片文件图标 这是我的代码:如何在vb.net中获取图片文件的图标,vb.net,filesystems,icons,Vb.net,Filesystems,Icons,我试图获取文件系统的图标并将其显示在我的列表框中 但我有一个空的图片文件图标 这是我的代码: Public Sub ExtractAssociatedIconEx() ' Initialize the ListView, ImageList and Form. listView1 = New ListView() imageList1 = New ImageList() listView1.Location = New Point(37, 12) list
Public Sub ExtractAssociatedIconEx()
' Initialize the ListView, ImageList and Form.
listView1 = New ListView()
imageList1 = New ImageList()
listView1.Location = New Point(37, 12)
listView1.Size = New Size(161, 242)
listView1.SmallImageList = imageList1
listView1.View = View.SmallIcon
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.listView1)
Me.Text = "Form1"
' Get the c:\ directory.
Dim dir As New System.IO.DirectoryInfo(TextBox1.Text)
Dim item As ListViewItem
listView1.BeginUpdate()
Dim file As System.IO.FileInfo
For Each file In dir.GetFiles()
' Set a default icon for the file.
Dim iconForFile As Icon = SystemIcons.WinLogo
item = New ListViewItem(file.Name, 1)
' Check to see if the image collection contains an image
' for this extension, using the extension as a key.
If Not (imageList1.Images.ContainsKey(file.Extension)) Then
' If not, add the image to the image list.
iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(file.FullName)
imageList1.Images.Add(file.Extension, iconForFile)
End If
item.ImageKey = file.Extension
listView1.Items.Add(item)
Next file
listView1.EndUpdate()
End Sub
如何获取图片文件的图标
谢谢有什么问题吗。对我来说,它工作得非常好。这段代码返回所有文件图标没有问题,但不返回图片图标,只返回一个空图标