c# - 带计时器的动画盒速度更快

标签 c# compact-framework

我有一个 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/

相关文章:

javascript - 如何使用一个 Controller 方法返回 FileResult 和 View

c# - 从 Accelerometer.ReadingChanged 调用 NavigationService.Navigate 会抛出 NotSupportedException

Windows CE 5 中的 C# 应用程序最终崩溃

c# - wcf 决定 : one service multiple contracts or many services

c# - MeasureString 忽略 Arial 和 Times New Roman 的字体样式

.net - .NET Compact Framework中的信号灯

c# - 如何在我的 Compact Framework 应用程序中使用 OpenStreetMap?

c# - 在 C# 中绘图的代码效率?

c# - 我应该如何正确测试 IoC 服务?

c# - 如何从 <?xml-stylesheet> 节点中获取 href 属性值?