日期:2014-05-18  浏览次数:20777 次

C#中,如何在同一个form里面,绘制不同速率的移动的图形?
最简单的情况,比如,如何绘制两个矩形,
他们的速度一个是2pixel/second, 另一个是10pixel/second,

该如何实现呢?
向大家请教,最好能提供一个例子,谢谢:)

------解决方案--------------------
C# code
PictureBox p2 = new PictureBox();
         PictureBox p1 = new PictureBox();
        private void Form1_Load(object sender, EventArgs e)
        {
            
            p1.BackColor = Color.Black;
            p1.Width = 30;
            p1.Height = 20;

            p1.Top = 5;
            this.Controls.Add(p1);


            p2.BackColor = Color.Red;
            p2.Width = 30;
            p2.Height = 20;
            p2.Top = 30;

            this.Controls.Add(p2);

            p1x = (float)p1.Left;
            p2x = (float)p2.Left;

            Timer t=new Timer();
            t.Interval=(40);
            t.Tick +=new EventHandler(t_Tick);
            t.Start();
        }

        float p1x;
        float p2x;

        private void t_Tick(object s, EventArgs e)
        {
            p1x =p1x+ (float)2 / 25;
            p2x = p2x + (float)10 / 25;

            this.p1.Left = (int)p1x;
            this.p2.Left = (int)p2x;
        }