winFrom中怎么可以让几个picturebox围绕一个原点转动起来
winFrom中怎么可以让几个picturebox围绕一个原点转动起来
[解决办法]
你自己写个定时器调用就可以了
public class MoveableObject
{
public static PointF Center;
public Image Image { get; set; }
public float Speed { get; set; }
public PointF Location { get; set; }
private float angle;
public float Angle
{
get { return angle; }
}
private float radius;
public float Radius { get { return radius; } }
public MoveableObject(Image image, PointF location, float speed)
{
this.Image = image;
this.Location = location;
this.Speed = speed;
float dx = location.X + Image.Width / 2 - Center.X;
float dy = location.Y + Image.Height / 2 - Center.Y;
radius = (float)Math.Sqrt(dx * dx + dy * dy);
angle = (float)(Math.Asin(dy / radius) * 180 / Math.PI);
}
public void Render(Graphics g)
{
g.DrawImage(Image, Location.X + Image.Width / 2, Location.Y + Image.Height / 2);
}
float __angle = 0;
public void Move()
{
float x = (float)Math.Cos(angle + __angle) * radius + Center.X;
float y = (float)Math.Sin(angle + __angle) * radius + Center.Y;
this.Location = new PointF(x, y);
__angle += Speed;
}
}