我目前正在使用Visual Studio 2015编写Windows窗体应用程序。该程序"生成"当用户点击不同的圆圈时,开始时会有24个圆圈逐一消失。问题是,当用户点击时,我不知道如何检查光标是否在椭圆上。
提前致谢!
答案 0 :(得分:1)
如果存储中心点和半径 1 ,则可以检查distance between the clicked point and all the centers。如果距离小于半径,则在圆圈范围内单击。
如果您需要跟踪重叠的圆圈并且只删除"顶部"上的那个,那么您还需要存储带有您的点和半径数据的z分量。
public class Circle {
public int X {get; set;}
public int Y {get; set;}
public int Z {get; set;}
public int Radius {get; set;}
}
将您的数据存储在List<Circle>
中。然后,您可以使用public bool Contains(int x, int y) { ... }
等方法轻松扩展Circle类,这使得将上述算法编写为LINQ查询非常容易。