日期:2014-05-17  浏览次数:21180 次

WinForm中contextMenuStrip控件的单击事件中,怎么获得contextMenuStript的所属控件?
问题概述:我动态生成了一些pictrueBox,他们都绑定了同一个contextMenuStrip,contextMenuStrip里有一个移除按钮,点击后移除相应的pictrueBox。
具体代码如下:
/// <summary>
        /// 创建新图片
        /// </summary>
        /// <param name="color">颜色</param>
        /// <param name="Width">宽度</param>
        /// <param name="Height">高度</param>
        private void Create_Pic(Color color, int Width, int Height)
        {
            PictureBox pb1 = new PictureBox();

            pb1.MouseDown += new MouseEventHandler(this.Control_MouseDown);
            pb1.MouseMove += new MouseEventHandler(this.Control_MouseMove);
            pb1.MouseUp += new MouseEventHandler(this.Control_MouseUp);

            pb1.BackColor = color;
            pb1.Size = new System.Drawing.Size(Width, Height);
            pb1.Parent = this;
            pb1.BorderStyle = BorderStyle.FixedSingle;
            pb1.BringToFront();
            //重点
            pb1.ContextMenuStrip = this.contextMenuStrip1;

            pb1.Show();
        }

private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            在这个事件中,我想要关闭被右键点击的PictureBox 
        }


请问大家如何写?
winform .Net C# ContextMenuStrip? PictrueBox

------解决方案--------------------
contextMenuStrip1.SourceControl