mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
25 lines
723 B
C#
25 lines
723 B
C#
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace GHelper.UI
|
|
{
|
|
public class IconHelper
|
|
{
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
|
|
|
private const uint WM_SETICON = 0x80u;
|
|
private const int ICON_SMALL = 0;
|
|
private const int ICON_BIG = 1;
|
|
|
|
|
|
public static void SetIcon(Form form, Bitmap icon)
|
|
{
|
|
SendMessage(form.Handle, WM_SETICON, ICON_SMALL, icon.GetHicon());
|
|
SendMessage(form.Handle, WM_SETICON, ICON_BIG, Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location)!.Handle);
|
|
}
|
|
|
|
}
|
|
}
|