我给你一个思路吧,在你所点击的控件的鼠标点击事件中将右键菜单和控件进行绑定,而不要在开始时绑定private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.ContextMenuStrip = contextMenuStrip1;
this.contextMenuStrip1.Show();
this.contextMenuStrip1.Top = this.Location.Y + e.Y;
this.contextMenuStrip1.Left = this.Location.X + e.X;
}
else
this.ContextMenuStrip = null;
}
{
if (e.Button == MouseButtons.Left)
{
this.ContextMenuStrip = contextMenuStrip1;
this.contextMenuStrip1.Show();
this.contextMenuStrip1.Top = this.Location.Y + e.Y;
this.contextMenuStrip1.Left = this.Location.X + e.X;
}
else
this.ContextMenuStrip = null;
}
在控件右侧显示属性的地方,找到ContextMenuStrip,然后选你的contextMenuStrip1
{
if (e.Button == MouseButtons.Left)
{
pictureBox6.ContextMenuStrip = contextMenuStrip2;
contextMenuStrip2.Show(Control.MousePosition);
} pictureBox6.ContextMenuStrip = null;
}