首页 新闻 会员 周边

C#旋转矩形

0
悬赏园豆:10 [已解决问题] 解决于 2009-04-07 11:14

我想实现矩形的旋转,根据中心点旋转,请大虾们帮帮忙!

问题补充: 但是这样的话,整个画板上的图形的坐标都会改变,我的意思是只想旋转选中的图形,而且想用鼠标拖拽实现
任务的主页 任务 | 初学一级 | 园豆:180
提问于:2009-03-30 11:36
< >
分享
最佳答案
0

做了一个简单的例子:在Form1 中放置一个 PictureBox 和 一个 Timer,

运行后会在 PictureBox 的中央画一个矩形,然后每秒旋转10度。 

   public partial class Form1 : Form
    {
        private float angle = 0;

        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.BackColor = Color.White;
            pictureBox1.Dock = DockStyle.Fill;
            timer1.Interval = 1000;
            timer1.Enabled = true;

        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {

            int width = 20;
            int height = 40;

            int x = (pictureBox1.Width - width) / 2;
            int y = (pictureBox1.Height - height) / 2;

            e.Graphics.TranslateTransform(x, y);
            e.Graphics.RotateTransform(angle);
            angle += 10;

            e.Graphics.DrawRectangle(new Pen(Color.Black, 1), new Rectangle(0 - width/2, 0 - height/2, width, height));
           
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Invalidate();
            pictureBox1.Update();
        }

eaglet | 专家六级 |园豆:17139 | 2009-03-30 12:31
其他回答(1)
0

楼上的很经典!可以试试!

子夜星辰 | 园豆:1613 (小虾三级) | 2009-03-30 14:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册