Moving Picture box with timer faster

喜夏-厌秋 提交于 2019-12-06 11:33:44

问题


I have a project in Compact framework 2.0 C# I am using a lot of picturebox in Form and there is a timer to change the location of pictureboxs every second but moving is very slowly how can I make faster it?

Timer interval is 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);
}

回答1:


Since you are using NET Compact Framework 2.0 you could improve your code by using SuspendLayout and ResumeLayout methods which are supported starting from version 2.0. Put these methods around your code as in the example:

//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();
}

This will prevent three redrawings of the form and instead perform only one.



来源:https://stackoverflow.com/questions/15548615/moving-picture-box-with-timer-faster

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!