我正在开发一个自定义控件,它可以在上面绘制曲线,并允许用户通过单击它来更改曲线的属性。现在捕获曲线上的事件本身是非常困难的,因为它们可能非常薄(根据用户需求)
不知何故,我想增加曲线的命中选择。我有一个解决方案,但它真的很昂贵,因为我的图表中有大量的曲线。这就是为什么我在寻找一种逻辑,通过它我可以找到鼠标指针周围的有限曲线。
我尝试了HitTest(),但没有任何帮助。我在谷歌上搜索了很多,但没有收获。
如果有人能在这个话题上发现一些亮点,并建议我一个正确的方向,那么这将是一个很大的帮助。
提前谢谢。
发布于 2012-02-27 23:44:50
您必须自己实现此功能。您可以做的是监听底层行的MouseEnter/MouseLeave,如果在初始MouseEnter/Leave的特定半径内按下鼠标,则将其视为命中。
例如,在伪代码中:
OnMouseEnter()
{
this.hittestPoint = currentMousePoint;
}
OnMouseLeave()
{
this.hitTestPoint = currentMousePoint;
}
OnMouseDown()
{
// Looking for mousedown within a 5 pixel radius of the line.
// Increase/decrease according to experimentation
const double radius = 5;
// Note see Euclidean distance for distance between vectors
// http://en.wikipedia.org/wiki/Euclidean_distance
double deltaX = (hitTestPoint.X - currentPoint.X);
double deltaY = (hitTestPoint.Y - currentPoint.Y);
double distance = Math.Sqrt(deltaX*deltaX + deltaY*deltaY);
if(distance < radius)
{
// Hittest detected!
}
}https://stackoverflow.com/questions/9200194
复制相似问题