为什么这个无限的彩虹背景循环无法正常工作,我在C#窗体中运行此代码,想法是在单击button1后变换背景颜色。我尝试了不同的无限循环制造商:for(;;)。但这里是代码:C#无限彩虹背景循环
private void button1_Click(object sender, EventArgs e)
{
while (true)
{
this.BackColor = System.Drawing.Color.Red;
System.Threading.Thread.Sleep(250);
this.BackColor = System.Drawing.Color.DarkRed;
System.Threading.Thread.Sleep(250);
this.BackColor = System.Drawing.Color.Orange;
System.Threading.Thread.Sleep(250);
this.BackColor = System.Drawing.Color.Yellow;
System.Threading.Thread.Sleep(250);
this.BackColor = System.Drawing.Color.Green;
System.Threading.Thread.Sleep(250);
this.BackColor = System.Drawing.Color.DarkGreen;
System.Threading.Thread.Sleep(250);
this.BackColor = System.Drawing.Color.Blue;
System.Threading.Thread.Sleep(250);
this.BackColor = System.Drawing.Color.DarkBlue;
System.Threading.Thread.Sleep(250);
this.BackColor = System.Drawing.Color.Violet;
}
谢谢。
运行此代码的应用程序的类型是什么? – ali
这种“不起作用”是如何体现的? –
此代码在哪里运行?在'OnPaint'? –