问题
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