I am trying to add items to my NotifyIcon
context menu like this:
notifyIcon = new()
{
Icon = Resources.NotifyIcon,
ContextMenuStrip = new()
{
Items = { { "Exit", Resources.Exit, Exit } }
},
Visible = true
};
For some reason, the image will always have a very subtle gray background. This happens even if I set the image to null
.
However, if I set its BackColor
to anything, even if to its original value, the gray background disappears:
notifyIcon = new()
{
Icon = Resources.NotifyIcon,
ContextMenuStrip = new()
{
Items = { { "Exit", Resources.Exit, Exit } }
},
Visible = true
};
Debug.WriteLine(notifyIcon.ContextMenuStrip.Items[0].BackColor.ToArgb());
notifyIcon.ContextMenuStrip.Items[0].BackColor = Color.FromArgb(255, 240, 240, 240);
Debug.WriteLine(notifyIcon.ContextMenuStrip.Items[0].BackColor.ToArgb());
The Debug.WriteLine
calls are there to verify that it is still the same color before and after I set the color.
Although this fixes the problem, it feels very hacky. What is the root cause of this problem, and is there a better way to solve this?