在這裡用到一個API函數
Public Declare Function SHGetFileInfo Lib "shell32" ( _
ByVal pszPath As String, _
ByVal dwFileAttributes As Integer, _
ByRef sfi As SHFILEINFO, _
ByVal cbsfi As Integer, _
ByVal uFlags As Integer) As Integer
'擷取圖示()
Dim ic2 As Icon
Dim HR_Small As Integer
Dim shfi_Small As New SHFILEINFO
HR_Small = SHGetFileInfo(strfile, 0, shfi_Small, Marshal.SizeOf(shfi_Small), SHGFI.SMALLICON Or SHGFI.ICON)
'strfile是要擷取圖示的檔案的路徑,可以是檔案夾,也可以是檔案.
Try
ic2 = Icon.FromHandle(shfi_Small.hIcon)
SmallImage.Images.Add(ic2) '把獲得的圖檔裝在ImageList裡
Catch ex As Exception
MsgBox(ex.ToString())
End Try
以後顯示的時候再來ImageList裡來取就是了