上下文菜单项选择事件

时间:2013-02-26 08:03:40

标签: c#

如何在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
                } 

1 个答案:

答案 0 :(得分:2)

您可以尝试以下内容:

var contextMenuStrip = (ContextMenuStrip) e.ClickedItem.GetCurrentParent();
var pictureBox = (PictureBox) contextMenuStrip.SourceControl;
pictureBox. //here you can access it.

此代码不会检查强制转换是否有效。