I have a .Net Winforms application with a ToolStrip that contains several ToolStripMenuItems.
I would like to be able to intercept Mouse LButton down events on the ToolStripMenuItems. I have PreFilterMessage defined. I assume I should be able to capture the event in that filter.
bool IMessageFilter.PreFilterMessage(ref Message message)
{
switch (message.Msg)
{
}
}
How would I do that?
Is there a custom message being used?
Once I capture the message, how can I use the Message data to get the actual ToolStripMenuItem that was clicked?
In the
IMessageFilterimplementation, use them.HWndproperty to get the owner control of the clickedToolStripItemby calling theControl.FromHandlemethod and cast it to a proper strip type. To the baseToolStripclass or one of its derives.Get the clicked point from the
m.LParamproperty to search the strip'sItemscollection and find the clicked item whose bounds should contain that point if any.If you just need to handle the items of the dropdown menus, then change the type of the owner control from the base
ToolStripto the derivedToolStripDropDownMenu.Or check the type of the returned item to also skip types like
ToolStripSeparator.Find out a different approach here.