I have a context menu with a few items. One of the items has a submenu (or whatever it’s called) with a few items (depends on what files it finds).
What I want to do is when I left click one of the sub-items I want one thing to happen, and when I right click I want another thing to happen.
My problem is that when I use the filesToolStripMenuItem_DropDownItemClicked, I don’t get any MouseEventArgs in the parameter, so I can’t find out which mouse button was used to click the item.
I tried adding it myself in the parameter but I get some error then.
Does anyone know how I can fix this? So I can find out what mouse button was used to click the sub-item (which is a ToolStripMenuItem)?
Thanks
edit: here is the code I use to create the sub items:
IPHostEntry ipE = Dns.GetHostEntry(Dns.GetHostName()); IPAddress[] IpA = ipE.AddressList; for (int i = 0; i < IpA.Length; i++) { if (!IpA[i].ToString().Contains(':')) cxItems.Items.Add(new ToolStripMenuItem(IpA[i].ToString())); }
And for those items I want to be able to do different things depending on which mouse button I use
That should help get you started.
RE: You’re edit:
The problem is, you’re just saying new ToolStripMenuItem(IpA[i].ToString()) without keep a reference to it. Here’s how you need to do it: