A memorandum when you want to use Notify icon in an environment where you cannot create icon files

1 minute read

When you want to make a little desktop application with C # in such an environment that there is no Visual Studio, you can not connect to the Internet, there is only a standard application for windows.

Icon file cannot be created with default windows10

If it is paint, it cannot be saved as an icon file, so the event that Notify icon cannot be displayed occurs.

How to create an icon file in Windows 10
Create icon file referring to the above

  1. Create an image with Paint and save it in 32x32 24-bitmap format
  2. Change the file extension from bmp to icon
  3. Create NotifyIcon as below

form.cs


this.notifyIcon = new NotifyIcon()
{
    Icon = new Icon("Icon image made.icon"),
    Visible = true,
    Text = "sample"
};

Error occurred

System.ArgumentException: 'Argument 'picture' must be a picture that can be used as a Icon.'

Convert bitmap files to icon files in code

For the time being, change the extension back to bmp⇒icon.

form.cs


var bitmap = new Bitmap("Icon image made.bmp");
this.notifyIcon = new NotifyIcon()
{
    Icon = Icon.FromHandle(bitMap.GetHicon()),
    Visible = true,
    Text = "sample"
};

The created icon is displayed in the task tray.

Summary

I was able to display Notify icon in an environment where icon files cannot be created.
It may be okay to make a tool to convert from bmp to icon
Since conversion is troublesome one by one, it may be easier to support it so that icons can be displayed even with bmp.