我使用DrawingVisual绘制了一些线条。现在我正在尝试实现一个简单的命中测试。
当鼠标指针在一条线上移动时,我会以两倍的厚度重新绘制它,以便让用户感觉突出显示(下图中的品红色线)
在我实现MouseRightButtonUp
事件之前,这非常有效。我想在用户右键单击该行时显示消息框。但不知何故,当鼠标悬停在线上且线条突出显示时,MouseRightButtonUp
事件根本不会提升。可能是什么问题?
MouseMove += OnMouseMove;
MouseRightButtonUp += OnMouseRightButtonUp;
private void OnMouseMove(object sender, MouseEventArgs e)
{
var p = e.GetPosition(Window);
// Check if the mouse hit any lines and redraw
ReDraw();
}
void OnMouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
// Check if any line is hit and show the message box
if (lineHit)
{
MessageBox.Show("You hit the line!");
}
}