程序代码: | [ 复制代码到剪贴板 ] |
Imports System.IO
Imports System.Runtime.InteropServices
Public Class Form1
Declare Function SHGetFileInfo Lib "Shell32.dll" (ByVal pszPath As String, ByVal dwFileAttributes As UInteger, ByRef psfi As SHFILEINFO, ByVal cbfileInfo As Integer, ByVal uFlags As UInteger) As IntPtr
Public Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
Public szDisplayName As String
Public szTypeName As String
End Structure
Private Enum SHGFI As Integer
SmallIcon = &H1
LargeIcon = &H0
Icon = &H100
DisplayName = &H200
Typename = &H400
SysIconIndex = &H4000
UseFileAttributes = &H10
End Enum
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim AppPath As String = My.Application.Info.DirectoryPath
Dim Dir As New DirectoryInfo(AppPath)
Dim File As FileInfo
'文件夹下所有文件
For Each File In Dir.GetFiles("*.*")
Dim FileName As String = File.FullName
Me.ListBox1.Items.Add(FileName)
Next
'文件夹下根文件夹
'Dim DirName As String
'For Each DirName In Directory.GetDirectories(AppPath)
' Me.ListBox1.Items.Add(DirName)
'Next
'文件夹下根文件夹
Dim Dir1 As DirectoryInfo
For Each Dir1 In Dir.GetDirectories
Me.ListBox1.Items.Add(Dir1.FullName)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim FileName As String = Me.ListBox1.SelectedItem.ToString
Me.PictureBox1.Image = GetIcon(FileName, False).ToBitmap
End Sub
Private Function GetIcon(ByVal strFilename As String, ByVal bSmallIcon As Boolean) As Icon
Dim info As SHFILEINFO = Nothing
Dim flags As SHGFI
If bSmallIcon Then
flags = SHGFI.Icon Or SHGFI.SmallIcon Or SHGFI.UseFileAttributes
Else
flags = SHGFI.Icon Or SHGFI.LargeIcon Or SHGFI.UseFileAttributes
End If
Form1.SHGetFileInfo(strFilename, 256, info, Marshal.SizeOf(info), flags)
Return Drawing.Icon.FromHandle(info.hIcon)
End Function
End Class
Imports System.Runtime.InteropServices
Public Class Form1
Declare Function SHGetFileInfo Lib "Shell32.dll" (ByVal pszPath As String, ByVal dwFileAttributes As UInteger, ByRef psfi As SHFILEINFO, ByVal cbfileInfo As Integer, ByVal uFlags As UInteger) As IntPtr
Public Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
Public szDisplayName As String
Public szTypeName As String
End Structure
Private Enum SHGFI As Integer
SmallIcon = &H1
LargeIcon = &H0
Icon = &H100
DisplayName = &H200
Typename = &H400
SysIconIndex = &H4000
UseFileAttributes = &H10
End Enum
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim AppPath As String = My.Application.Info.DirectoryPath
Dim Dir As New DirectoryInfo(AppPath)
Dim File As FileInfo
'文件夹下所有文件
For Each File In Dir.GetFiles("*.*")
Dim FileName As String = File.FullName
Me.ListBox1.Items.Add(FileName)
Next
'文件夹下根文件夹
'Dim DirName As String
'For Each DirName In Directory.GetDirectories(AppPath)
' Me.ListBox1.Items.Add(DirName)
'Next
'文件夹下根文件夹
Dim Dir1 As DirectoryInfo
For Each Dir1 In Dir.GetDirectories
Me.ListBox1.Items.Add(Dir1.FullName)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim FileName As String = Me.ListBox1.SelectedItem.ToString
Me.PictureBox1.Image = GetIcon(FileName, False).ToBitmap
End Sub
Private Function GetIcon(ByVal strFilename As String, ByVal bSmallIcon As Boolean) As Icon
Dim info As SHFILEINFO = Nothing
Dim flags As SHGFI
If bSmallIcon Then
flags = SHGFI.Icon Or SHGFI.SmallIcon Or SHGFI.UseFileAttributes
Else
flags = SHGFI.Icon Or SHGFI.LargeIcon Or SHGFI.UseFileAttributes
End If
Form1.SHGetFileInfo(strFilename, 256, info, Marshal.SizeOf(info), flags)
Return Drawing.Icon.FromHandle(info.hIcon)
End Function
End Class
【启动面板.rar】点击下载此文件
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |