我需要移動我的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 +。 –