【发布时间】:2014-12-16 23:08:09
【问题描述】:
我正在尝试制作一个非常简单的逻辑游戏。这个想法是看到一个带有一定数量彩色方块(按钮)的矩阵,然后隐藏它们,玩家必须点击彩色方块。所以我需要在绘制正方形/按钮和返回原始颜色之间有 2 秒的延迟。所有代码都在button_click 事件中实现。
private void button10_Click(object sender, EventArgs e)
{
int[,] tempMatrix = new int[3, 3];
tempMatrix = MakeMatrix();
tempMatrix = SetDifferentValues(tempMatrix);
SetButtonColor(tempMatrix, 8);
if (true)
{
Thread.Sleep(1000);
// ReturnButtonsDefaultColor();
}
ReturnButtonsDefaultColor();
Thread.Sleep(2000);
tempMatrix = ResetTempMatrix(tempMatrix);
}
这是整个代码,但我需要在调用SetButtonColor() 和ReturnButtonsDefaultColor() 之间有一些延迟。到目前为止,我对Thread.Sleep() 的所有实验都没有成功。我在某些时候遇到了延迟,但从未显示彩色方块/按钮。
【问题讨论】:
-
在代码完成之前不会绘制 UI。