带有计时器的移动图片框更快
我在Compact framework 2.0 C#中有一个项目我在Form中使用了很多图片框,并且有一个计时器可以每秒更改图片框的位置,但移动非常慢,我怎样才能更快?
定时器间隔为100
private void timer1_Tick(object sender, EventArgs e) { picust.Location = new Point(picust.Location.X, picust.Location.Y + 10); picx.Location = new Point(picx.Location.X, picx.Location.Y + 10); picy.Location = new Point(picy.Location.X, picx.Location.Y + 10); }
由于您使用的是.NET Compact Framework 2.0,因此可以使用从2.0版开始支持的SuspendLayout
和ResumeLayout
方法来改进代码。 将这些方法放在代码中,如下例所示:
//assuming that this code is within the parent Form private void timer1_Tick(object sender, EventArgs e) { this.SuspendLayout(); picust.Location = new Point(picust.Location.X, picust.Location.Y + 10); picx.Location = new Point(picx.Location.X, picx.Location.Y + 10); picy.Location = new Point(picy.Location.X, picx.Location.Y + 10); this.ResumeLayout(); }
这将阻止三次重绘表单,而只执行一次。