我有一個程序,可以隨意移動圖片框中的gif,但是當函數被調用時,gif會凍結。但是,當我使用keyDown函數移動框來移動圖片框時,它仍然是動畫的。如何在移動時保持動畫效果?如何在不暫停的情況下移動動畫GIF?
這是我用它來移動一個隨機距離,凍結GIF。
void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A)
{
eventDuration = randomizer.Next(30, 70);
while (eventDuration != 0)
{
MoveLeft();
eventDuration = eventDuration - 1;
Thread.Sleep(15);
}
}
}
private void MoveLeft()
{
_y = picPicture.Location.Y;
_x = picPicture.Location.X;
picPicture.Location = new System.Drawing.Point(_x - 1, _y);
}
然而,如果利用這一點,它平滑地移動而不凍結GIF,甚至當我按住A鍵。因爲它需要不斷的用戶輸入我不能使用這種方法,而首先是自主的方向它移動
void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A)
{
MoveLeft();
}
}
private void MoveLeft()
{
_y = picPicture.Location.Y;
_x = picPicture.Location.X;
picPicture.Location = new System.Drawing.Point(_x - 1, _y);
}
我如何才能將我的圖片框隨機距離無需暫停GIF?