我想减慢foreach循环,所以我可以显示大约2秒完成的gif但是foreach循环非常快我看不到gif,除了最后一个。
foreach (string s in words)
{
path = Dictionary.wordchecker(s);//Checks words for Animation
pictureBox1.Image = Image.FromFile(Directory.GetCurrentDirectory() + "\\images\\" + path + ".gif");
textBox1.Text = s;
}
答案 0 :(得分:2)
根据要求我更新了解决方案以使用Windows窗体, 你可以这样做,假设你有一个字符串列表,如下所示:
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
List<string> words = new List<string>();
int cur = 0;
public static int Main()
{
//2000 is two seconds you can adjust to the amount you need
timer.Interval = 2000;
timer.Tick += timerTick;
timer.Start();
}
private void timerTick(object sender, object e)
{
if (cur < words.Count)
{
path = Dictionary.wordchecker(words[cur]);//Checks words for Animation
pictureBox1.Image = Image.FromFile(Directory.GetCurrentDirectory() + "\\images\\" + path + ".gif");
textBox1.Text = s;
cur++;
}
else
{
timer.Stop();
}
}