如何在椭圆后移动图片框

时间:2016-05-18 08:33:50

标签: c# winforms drawing

假设我有这个Ellipse:

Graphics g = this.CreateGraphics();
        g.DrawEllipse(new Pen(Color.Black), 100, 200, 500, 200);

如何在完全遵循Ellipse的线条后移动pictureBox1?

1 个答案:

答案 0 :(得分:1)

您可以使用GraphicsPath代替pictureBox跟随椭圆的路径:

using System.Drawing.Drawing2D;

//

GraphicsPath path = new GraphicsPath();
path.AddEllipse(new Rectangle(100, 200, 500, 200));

foreach (PointF point in path.PathPoints)
{
    pictureBox1.Location = Point.Round(point);
    Thread.Sleep(100); // just for the demonstration
}