首页 > 解决方案 > 如何以编程方式显示 ContextMenuStrip 的 DropDown?

问题描述

我需要一个按钮来在鼠标左键单击而不是右键单击时显示与其关联的 ContextMenuStrip。我怎样才能做到这一点?

标签: c#winformscontextmenustrip

解决方案


试试下面的代码

Point location = button1.PointToScreen(Point.Empty);
contextMenuStrip1.Show(location);

PointToScreen 获取按钮的实际位置并显示按钮所在的上下文菜单条。


推荐阅读