本文介绍了右键单击图片框上的显示上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获得一个Contextmenu右键单击Windows应用程序中的图片框。必须显示所有图片框的相同上下文菜单。
How can I get a Contextmenu on Right click the picture box in windows application.The same contextmenu has to display for all the picture boxes.
推荐答案试试这个.. try this.. pictureBox1.ContextMenustrip=contextMenuStrip1;
这不是这很难,但很容易忘记。 例如,假设您有一个图片框,并且您已经在其上绘制了一些内容,并希望用户能够在选择某个内容时拥有一个上下文菜单,而不是选择。您可以在选择/未选择内容时为上下文菜单指定图片框。或者你可以在右键单击显示它们菜单。 我在这里显示第二件事因为我发现维护时不易出错,只是我个人的选择。 在任何一种情况下,你都要创建一个上下文菜单对象,填写它,创建处理程序等。 This isn't that hard, but easy to forget. For example, lets say you have a picture box, and you have drawn things on it and want the user to be able to have a context menu for when a thing is selected and a different one when not selected. You could assign the picture box the context menu as things are selected / not selected. Or you could do it on the right click show them menu. I'm showing that second thing here because I find it less error prone when maintaining, just my personal choice. In either case you'd create a context menu object, fill it in, create the handlers, etc. if (e.Button == MouseButtons.Right) { mPointWhenClicked = new Point(e.X, e.Y); if (mObjectAlreadySelectedInImage != null) { contextMenuWhenSelected.Show(pictureBox1, e.X, e.Y); } else { contextMenuWhenNotSelected.Show(pictureBox1, e.X, e.Y); } }
更多推荐
右键单击图片框上的显示上下文菜单
发布评论