2

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
                } 
4

1 に答える 1

2

次のようなものを試すことができます:

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

このコードは、キャストが有効かどうかをチェックしません。

于 2013-02-26T08:17:16.060 に答える