假设我有这个Ellipse:
Graphics g = this.CreateGraphics();
g.DrawEllipse(new Pen(Color.Black), 100, 200, 500, 200);
如何在完全遵循Ellipse的线条后移动pictureBox1?
答案 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
}