我需要移动我的Windows窗体应用程序中的图片。快速移动图片
这工作,但速度非常慢。有什么方法可以更快地移动图片?我想这样做是因为我想达到“飞翔效果”。
// First try
for (int i = 0; i < 500; i++)
{
//Tempbox is a picturebox
this.Tempbox.Location = new Point(this.Tempbox.Left++, 0);
Application.DoEvents();
System.Threading.Thread.Sleep(50);
}
// Second try
using (Graphics g = Graphics.FromImage(BufferBm))
{
for (int i = 0; i < 500; i++)
{
g.DrawImage(tempContolImage, new System.Drawing.Point(i, 0));
this.Tempbox.Image = BufferBm;
Application.DoEvents();
System.Threading.Thread.Sleep(50);
}
}
您需要处理的'Paint'事件,并借鉴控制,然后在一个定时器上使'Invalidate()'失效。 – SLaks
尝试在每次迭代中移动多个像素。越接近最终设置,减少像素量以使其更柔和。它在WinForms中永远不会非常流畅。考虑使用计时器而不是循环,[DoEvents](http://stackoverflow.com/q/5181777/719186)存在问题。 – LarsTech
如果您想要真正快速的绘图,而不是使用directx,请使用GDI而不是GDI +。 –