StatusStrip의 ToolStripStatusLabel 위치에 ContextMenuStrip을 표시하려고합니다. 일반 컨트롤에는 PointToScreen/PointToClient/etc가 있지만 ToolStripStatusLabel은 Component에서 파생되므로 일반적으로 사용하지 않습니다.StatusBar 항목의 위치에 ContextMenuStrip 표시
도움을 주시면 감사하겠습니다.
StatusStrip의 ToolStripStatusLabel 위치에 ContextMenuStrip을 표시하려고합니다. 일반 컨트롤에는 PointToScreen/PointToClient/etc가 있지만 ToolStripStatusLabel은 Component에서 파생되므로 일반적으로 사용하지 않습니다.StatusBar 항목의 위치에 ContextMenuStrip 표시
도움을 주시면 감사하겠습니다.
당신은 같은 것을 할 수 없습니다 :
int x = label.Bounds.Location.X + statusStrip.Location.X;
int y = label.Bounds.Location.Y + statusStrip.Location.Y;
menu.Show(this, x, y);
체크 아웃 ToolStripStatusLabel의 Bounds 속성을. 당신이해야 할 일을이처럼 사용하여 그것이 ToolStripStatusLabel 클릭 때 폼에서 마우스의 적절한 위치를 얻기에 관련된 몇 가지 단계가 있습니다
contextMenuStrip1.Show(statusStrip1, toolStripStatusLabel2.Bounds.X, toolStripStatusLabel2.Bounds.Y);
. 언급 한대로 ToolStripStatusLabel에는 PointToClient 또는 PointToScreen 메서드가 없지만 부모 StatusStrip 컨트롤이 있습니다.
시도 : 나는이 같은 문제를 투쟁과이 문제를 봤 우연히해서
private void toolStripStatusLabel_MouseDown(object sender, MouseEventArgs e)
{
Point p = e.Location;
p.Offset(toolStripStatusLabel.Bounds.Location);
myContextMenu.Show(StatusStrip.PointToScreen(p));
}
매우, 매우 늦게 대답. 내가 가장 좋은 해결책으로 찾은 것은 지금까지 해답에 대한 멋진 비꼬는 말을 추가합니다. 여기있다 :
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의 왼쪽 위 모서리에있는 메뉴가 표시됩니다. 기록을 위해.