2

im having 24 controls(pictureboxes) using the same strip menu, on the click event of any item in that strip menu i would want to know which control that used this strip menu item for instance

private void getInfoToolStripMenuItem_Click(object sender, EventArgs e)
{
    ...
}

how to determine which control from the 24 controls that's using this menu if it's not possible, is there any way around that to achieve the same purpose ? (to have all the controls sharing the same code without having 24 menu for the 24 controls with writing the code in all of them)

thanks and have a wonderful day

edit: for sake of clarification here is a rephrase of the problem "a groupbox with 24 pictureboxes inside, all sharing same strip menu, i would want to determine which picturebox clicked the strip menu item so i can use that in the code to do something with the name of control (matching it with a keyvaluepair list)" here is a picture enter image description here

all i want to know which picturebox of those had clicked getinfo, that's it

4

1 回答 1

1

在一些回复之后,很明显您想要点击ContextMenuStrip弹出的控件。您只需使用该SourceControl属性即可获得该控制权。

private void getInfoToolStripMenuItem_Click(object sender, EventArgs e) {
  PictureBox pb = contextMenuStrip1.SourceControl as PictureBox;
}
于 2013-09-18T13:19:35.910 回答