我喜欢在Windows窗体项目中使用Sleep()函数,但Sleep()先于其他任何东西执行.我读到我应该使用fflush()进行刷新,但我不知道要刷新什么.有人能帮我吗?
代码:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->label1->Visible= false;
this->button1->Visible= false;
r = (float)rand()/(float)RAND_MAX;
r = r*100000;
i = r;
r = r - i;
String^ strR = "" + r;
this->label2->Text = strR;
if(r >= 0.5)
{
this->pictureBox1->Visible= true;
this->pictureBox1->BackColor = System::Drawing::Color::Blue;
}
else
{
this->pictureBox1->Visible= true;
this->pictureBox1->BackColor = System::Drawing::Color::Red;
}
Sleep(500);
}
Run Code Online (Sandbox Code Playgroud)