我做了一个图片滚动的控件,主要是通过timer控制picturebox的坐标实现,timer的频率非常高,非常占CPU使用率。有没有更好的方法?

解决方案 »

  1.   

    开个线程执行这个事,Sleep1秒
      

  2.   

    具体我是这样写的
    interval = 1        private void roll()
            {
                bool end = false;
                if (pp1.Y >= this.Height)
                {
                    pp1.Y = -this.Height;
                    pictureBox2.BringToFront();
                    pictureBox1.Image = ImageList.Images[++next >= ImageList.Images.Count ? next = 0 : next];
                    if (step == 1)
                    {
                        end = true;
                    }
                }
                else if (pp2.Y >= this.Height)
                {
                    pp2.Y = -this.Height;
                    pictureBox1.BringToFront();
                    pictureBox2.Image = ImageList.Images[++next >= ImageList.Images.Count ? next = 0 : next];
                    if (step == 1)
                    {
                        end = true;
                    }
                }
                pp1.Y += step;
                pp2.Y += step;
                if (pp1.Y>0&&pp1.Y-step<0)
                {
                    pp1.Y = 0;
                }
                else if (pp2.Y > 0 && pp2.Y - step < 0)
                {
                    pp2.Y = 0;
                }
                pictureBox1.Location = pp1;
                pictureBox2.Location = pp2;
                if (end)
                {
                    timer1.Stop();
                }
            }        private void timer1_Tick(object sender, EventArgs e)
            {
                roll();
            }
      

  3.   

    不要用移动控件的方式,
    开线程用GDI+绘制,流畅还不怎么占CPU