我想在StatusStrip中的ToolStripStatusLabel所在位置显示一个ContextMenuStrip。普通控件有PointToScreen / PointToClient /等,但由于ToolStripStatusLabel是从组件派生的,所以没有。
任何帮助都将不胜感激。
发布于 2011-08-18 17:18:00
一个非常,非常晚的答案,只是因为我碰巧遇到了同样的问题,并在谷歌上搜索了这个问题。到目前为止,我发现的最好的解决方案为答案增加了一个很好的转折。这就是它:
void toolStripItem_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
var label = (ToolStripItem)sender;
this.contextMenuStrip1.Show(this.mainStatusStrip, label.Bounds.X + e.X, label.Bounds.Y + e.Y);
}
}将鼠标相对于控件的坐标(e.X,e.Y)添加到边界坐标,使菜单显示在正确的位置。省略此选项将显示ToolStripItem左上角的菜单。记录在案。
发布于 2009-07-23 03:20:11
你就不能这样做吗:
int x = label.Bounds.Location.X + statusStrip.Location.X;
int y = label.Bounds.Location.Y + statusStrip.Location.Y;
menu.Show(this, x, y);发布于 2009-07-23 03:33:59
查看ToolStripStatusLabel的Bounds属性。像这样使用它来做你需要做的事情:
contextMenuStrip1.Show(statusStrip1, toolStripStatusLabel2.Bounds.X, toolStripStatusLabel2.Bounds.Y); https://stackoverflow.com/questions/1169323
复制相似问题