Immagine anteprima C#

lunedì 14 settembre 2009 - 15.00

augusto890 Profilo | Junior Member

Buongiorno a tutti,
io ho la necessità nel mio programma di recuperare l'iconcina di anteprima del file selezionato.
Proprio come fa windows quando selezioni un file .ppt o pdf...voi sapete se in .NET o altro esiste qualche classe che permette di fare un qualcosa di simile?

Grazie in anticipo, Luca

reru Profilo | Newbie

ciao, prova così

in un modulo

Private Structure SHFILEINFO
Public hIcon As IntPtr 'Icon
Public iIcon As Integer 'Icon Index
Public dwAttributes As Integer 'Flags
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public szDisplayName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
Public szTypeName As String
End Structure



Public Function ExtractIcon(ByVal Pic As PictureBox, ByVal Path As String) As Long ', ByVal IconSize As IconSize
Try
Dim rImg As IntPtr
Dim shInfo As New SHFILEINFO
rImg = SHGetFileInfo(Path, 0, shInfo, Marshal.SizeOf(shInfo), &H100)
'Get Icon And Add It To Small ImageList
Dim eI As System.Drawing.Icon = System.Drawing.Icon.FromHandle(shInfo.hIcon)
Pic.Image = eI.ToBitmap

Catch ex As Exception
Pic.Image = Nothing
Exit Function
'MessageBox.Show("Error: " & ex.Message, "Titolo", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Function

ciao
RZ
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5