我正在尝试创建一个倒计时,其中显示文本“GAME STARTS IN:”并使用 for 循环和 Thread.Sleep 变量从三个倒计时。我首先使用设计器创建“游戏开始于:”部分,但在变量不显示后,我将其移至代码中。现在什么都没有出现。这就是我现在的计时器方法中的内容:
if (!countedDown)
DoCountdown();
Countdown.Hide();
然后在 DoCountdown 方法中:
this.Countdown.BackColor = System.Drawing.Color.Transparent;
this.Countdown.ForeColor = System.Drawing.Color.White;
this.Countdown.Location = new System.Drawing.Point(360, 17);
this.Countdown.Name = "Countdown";
this.Countdown.Font = new System.Drawing.Font("Segoe UI", 12F,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point);
this.Countdown.Size = new System.Drawing.Size(185, 24);
this.Countdown.TabIndex = 6;
countedDown = true;
for (int i = 3; i > 0; i--)
{
Countdown.Text = "GAME STARTS IN: " + i;
System.Threading.Thread.Sleep(1000);
}
我在 System.Threading.Thread.Sleep(100) 处设置了一个断点,一切看起来都很正常。Countdown.Text 等于“GAME STARTS IN: 3”。尝试集成解决方案后,文本未显示。这是我的代码中的更多上下文:
这是我的开始屏幕表格
private void QuitGame(object sender, EventArgs e)
{
Application.Exit();
}
private void StartMultiplayerGame(object sender, EventArgs e)
{
GameScreen startGame = new GameScreen();
startGame.Show();
Hide();
}