Skip to content

Instantly share code, notes, and snippets.

@krisdb2009
Created November 22, 2019 21:51
Show Gist options
  • Save krisdb2009/88aca0a681e38d33add72a095d6480f5 to your computer and use it in GitHub Desktop.
Save krisdb2009/88aca0a681e38d33add72a095d6480f5 to your computer and use it in GitHub Desktop.
Allows Menu Item's to have icons.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
namespace SuperGrate
{
static class MenuItemBitmap
{
[DllImport("user32.dll")]
private static extern int SetMenuItemBitmaps(IntPtr hMenu, IntPtr nPosition, int wFlags, IntPtr hBitmapUnchecked, IntPtr hBitmapChecked);
public static void SetBitmap(this MenuItem MenuItem, Bitmap Bitmap, Bitmap UncheckedBitmap = null)
{
if(UncheckedBitmap == null)
{
SetMenuItemBitmaps(MenuItem.Parent.Handle, (IntPtr)MenuItem.Index, 0x00000400, Bitmap.GetHbitmap(), Bitmap.GetHbitmap());
}
else
{
SetMenuItemBitmaps(MenuItem.Parent.Handle, (IntPtr)MenuItem.Index, 0x00000400, Bitmap.GetHbitmap(), UncheckedBitmap.GetHbitmap());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment