convert VB to C#
This commit is contained in:
33
Pilz.Win32/Internals/IconExtractor.cs
Normal file
33
Pilz.Win32/Internals/IconExtractor.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using global::System.Drawing;
|
||||
using global::System.Runtime.InteropServices;
|
||||
using global::Pilz.Win32.Native;
|
||||
|
||||
namespace Pilz.Win32.Internals
|
||||
{
|
||||
public class IconExtractor
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Extrahiert das Icon aus einer Datei oder aus einem Ordner.
|
||||
/// </summary>
|
||||
/// <param name="FilePath">Hier übergeben Sie den Pfad der Datei von dem das Icon extrahiert werden soll.</param>
|
||||
/// <param name="Small">Bei übergabe von true wird ein kleines und bei false ein großes Icon zurück gegeben.</param>
|
||||
public static Icon ExtractIcon(string FilePath, bool Small)
|
||||
{
|
||||
Icon icon;
|
||||
var shinfo = new SHFILEINFO();
|
||||
LibShell32.SHGetFileInfo(FilePath, 0U, ref shinfo, (uint)Math.Truncate((decimal)Marshal.SizeOf(shinfo)), SHFILEINFO.SHGFI_ICON | (Small ? SHFILEINFO.SHGFI_SMALLICON : SHFILEINFO.SHGFI_LARGEICON));
|
||||
try
|
||||
{
|
||||
icon = Icon.FromHandle(shinfo.hIcon);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
icon = null;
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
Imports System.Drawing
|
||||
Imports System.Runtime.InteropServices
|
||||
Imports Pilz.Win32.Native
|
||||
|
||||
Namespace Internals
|
||||
|
||||
Public Class IconExtractor
|
||||
|
||||
''' <summary>
|
||||
''' Extrahiert das Icon aus einer Datei oder aus einem Ordner.
|
||||
''' </summary>
|
||||
''' <param name="FilePath">Hier übergeben Sie den Pfad der Datei von dem das Icon extrahiert werden soll.</param>
|
||||
''' <param name="Small">Bei übergabe von true wird ein kleines und bei false ein großes Icon zurück gegeben.</param>
|
||||
Public Shared Function ExtractIcon(FilePath As String, Small As Boolean) As Icon
|
||||
Dim icon As Icon
|
||||
Dim shinfo As New SHFILEINFO
|
||||
|
||||
LibShell32.SHGetFileInfo(FilePath, 0, shinfo, Math.Truncate(Marshal.SizeOf(shinfo)), SHFILEINFO.SHGFI_ICON Or If(Small, SHFILEINFO.SHGFI_SMALLICON, SHFILEINFO.SHGFI_LARGEICON))
|
||||
|
||||
Try
|
||||
icon = Icon.FromHandle(shinfo.hIcon)
|
||||
Catch ex As Exception
|
||||
icon = Nothing
|
||||
End Try
|
||||
|
||||
Return icon
|
||||
End Function
|
||||
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user