VB.NET 获取文件图标
Imports System.Drawing
Imports System.Runtime.InteropServices
Public Class Form1
Private Shared Function ExtractIconEx(ByVal lpszFile As String, ByVal nIconIndex As Integer, ByRef phiconLarge As IntPtr, ByRef phiconSmall As IntPtr, ByVal nIcons As UInteger) As UInteger
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim filePath As String = "C:pathtoyourfile.txt" ' 替换为您的文件路径
Dim iconIndex As Integer = 0 ' 图标索引,通常为 0
Dim largeIconHandle As IntPtr = IntPtr.Zero
Dim smallIconHandle As IntPtr = IntPtr.Zero
ExtractIconEx(filePath, iconIndex, largeIconHandle, smallIconHandle, 1)
If largeIconHandle <> IntPtr.Zero Then
Dim largeIcon As Icon = Icon.FromHandle(largeIconHandle)
PictureBox1.Image = largeIcon.ToBitmap() ' 将图标显示在 PictureBox 控件中
DestroyIcon(largeIconHandle)
End If
End Sub
Private Shared Function DestroyIcon(ByVal hIcon As IntPtr) As Boolean
End Function
End Class
366.38KB
文件大小:
评论区