我正在使用 .NET Framework 4.0 在 Visual Studios Community 2019 上開發一個小型 C /CLR Windows 表單專案,其中我有一個組合框和一個標簽。
下面的代碼片段作業正常:
private: System::Void comboBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
label1->Text = "comboBox1->Text";
}
但是如果我添加Sleep(1000);after label1->Text = "comboBox1->Text";,我希望標簽在睡眠期之前改變,但在睡眠期結束后它會改變。
通常,在label1->Text = "comboBox1->Text";該行下方的任何內容之后執行。
對于下面的代碼片段,我希望程式在更改 label1 文本后休眠。
private: System::Void comboBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
label1->Text = "comboBox1->Text";
Sleep(1000);
}
uj5u.com熱心網友回復:
我明白你的意思。要實作此功能,您需要使用timer. 您需要將 a 添加timer到您的 WinForm,然后在 timer 屬性中將 Interval 值設定為 1000。您需要使用Start啟動計時器,您可以參考我的代碼。
this->timer1->Interval = 1000;
this->timer1->Tick = gcnew System::EventHandler(this, &MyForm::timer1_Tick);
timer1->Start();
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { label1->Text = comboBox1->Text; }
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/341548.html
上一篇:無法部署不存在的路徑
