How do I rotate a picturebox around a point?

时光怂恿深爱的人放手 提交于 2019-12-02 04:07:23
TaW

This may help:

float angle = 0;
float rotSpeed = 1;
Point origin = new Point(222, 222);  // your origin
int distance = 100;                  // your distance

private void timer1_Tick(object sender, EventArgs e)
{
    angle += rotSpeed;
    int x = (int)(origin.X + distance * Math.Sin(angle *Math.PI / 180f));
    int y = (int)(origin.Y + distance * Math.Cos(angle *Math.PI / 180f));
    yourControl.Location = new Point(x, y);
}

Pick your timer Interval and don't be disappointed that it will look a little uneven. Winforms is really bad at animation..

If you want the image to rotate as well you can find an example here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!