我有一个 Compact Framework 2.0 C# 项目 我在表单中使用了很多图片框,并且有一个计时器每秒更改图片框的位置,但移动速度非常慢,如何才能使其更快?
定时器间隔为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,因此您可以使用 SuspendLayout
来改进代码。和 ResumeLayout
从2.0版本开始支持的方法。将这些方法放在您的代码中,如示例所示:
//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();
}
这将防止表单重绘三次,而只执行一次。
关于c# - 带计时器的动画盒速度更快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15548615/