【发布时间】:2011-02-08 17:45:34
【问题描述】:
我有一个包含许多图片框的面板。每个图片框都注册了“contextRightMenu”作为它们的上下文菜单。
当上下文菜单弹出时我想要的是获取当前的鼠标位置。
我曾尝试使用 mouseDown 并单击来获取鼠标位置,但这些事件发生在单击上下文菜单的一项后,为时已晚。
上下文菜单的弹出事件不传递鼠标事件参数,所以我不知道如何获取鼠标位置。
如果我能得到鼠标事件参数就很容易了。
那我就可以了:
this.contextRightClick.Popup += new System.EventHandler(this.contextRightClick_Popup);
// If EventArgs include mouseposition within the sender
private void contextRightClick_Popup)(object sender, EventArgs e)
{
int iLocationX = sender.Location.X;
int iLocationY = sender.Location.Y;
Point pPosition = new Point(iLocationX + e.X, iLocationY + e.Y); // Location + position within the sender = current mouseposition
}
谁能帮我获取一些鼠标事件参数,或者建议一个在上下文菜单弹出之前运行的事件?
提前致谢
【问题讨论】:
标签: c# compact-framework event-handling location