The notorious and famous ToolStripMenuItem class. Although it looks great in a strip it does not always behave like you think it should. It has somewhat a mind of it’s own.
The annoying thing with this class is that even when the ToolStripMenuItem is disabled, it still light’s up when you hover your mouse over it. I searched high and low and was affraid I had to pull of some black magic to get it to behave to my whishes but fortunately there is an easier (and much prettier) way:
[csharp]public class ProperMenuItem : ToolStripMenuItem
{
public ProperMenuItem(string text, Image image, EventHandler onClick)
: this(text, image, onClick, null)
{
}
public ProperMenuItem(string text, Image image, EventHandler onClick, Keys shortcutKeys)
: base(text, image, onClick, shortcutKeys)
{
}
public override bool CanSelect
{
// without this line the items still receive
// focus even though they are clearly disabled
get { return this.Enabled; }
}
}[/csharp]
I assumed more people must have wandered into this but all I found was a lone cry for help without any responses. So I wrestled with this class for a few hours (yes, pathetic, I know) and finally (by trial and error really) found an acceptable solution.