首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

winFrom中如何可以让几个picturebox围绕一个原点转动起来

2013-12-26 
winFrom中怎么可以让几个picturebox围绕一个原点转动起来winFrom中怎么可以让几个picturebox围绕一个原点

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;
        }
    }

热点排行