如何在c#.net 3.5中使用该工具条的itemselect事件中使用该工具条附加的控件的属性?
picArray[n].ContextMenuStrip = new ContextMenuStrip();
ToolStripItem Schedule = picArray[n].ContextMenuStrip.Items.Add("Schedule");
picArray[n].ContextMenuStrip.Items.Add("Schedule");
picArray[n].ContextMenuStrip.ItemClicked += (sender, e) =>
{
panel1.Show();
if (e.ClickedItem == Schedule)
{
//Here I want to use property of that picturebox on which right
//click is done
}
答案 0 :(得分:2)
您可以尝试以下内容:
var contextMenuStrip = (ContextMenuStrip) e.ClickedItem.GetCurrentParent();
var pictureBox = (PictureBox) contextMenuStrip.SourceControl;
pictureBox. //here you can access it.
此代码不会检查强制转换是否有效。