【发布时间】:2017-09-01 21:05:51
【问题描述】:
我有一个画布 myCanvas,我想在我指定点的位置绘制多个多边形。
PointCollection polygonpoints = new PointCollection();
private void myCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
//add polygon collection
Point p = e.GetPosition(MapGrid);
polygonpoints.Add(p);
}
private void myCanvas_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
Polygon poly = new Polygon();
poly.Points = polygonpoints;
poly.Fill = Brushes.AliceBlue;
MapCanvas.Children.Add(poly);
polygonpoints.Clear(); // this is making clear the polygon but the pointcollection is remain
}
polygonpoints.Clear - 我计划用它来清除下一个多边形的多边形点。但这并没有发生。
请有任何建议。
【问题讨论】:
-
到底发生了什么?
-
下一步肯定是在左键单击时显示当前多边形。您将首先创建一个新的多边形并将其添加到画布中。保留对当前多边形的引用作为类成员(而不是 PointCollection)。在每次左键单击时将一个点添加到其 Points 属性。右键单击,创建并添加一个新的多边形并对其进行操作。