【发布时间】:2019-10-03 05:50:57
【问题描述】:
我在 panel2 上的 SplitContainer 中有一个 Button。
我已经动态创建了一个ContextMenuStrip,并将其附加到此按钮。我想将上下文菜单定位在此图像中的按钮下方
但我得到的不是那样。
这是我尝试过的:
private void SelectContentGroup_Click(object sender, EventArgs e) {
ContextMenuStrip x = selectContentGroup.ContextMenuStrip;
if (x is null) return;
// this will show contextmenu near the mouse arrow
//x.Show(Control.MousePosition);
// I have tried to get MousePosition and to compare to my button location and Y is a lot of difference, about 200 pixels
//Console.WriteLine("MousePosition: {0}, ButtonLocation: {1}", Control.MousePosition, PointToScreen(selectContentGroup.Location));
x.Show(PointToScreen(selectContentGroup.Location));
// I tried with e.Location also, but none of those points will give the button Left-Bottom position for contextmenu
}
【问题讨论】:
标签: c# winforms contextmenustrip