mình muốn viết đoạn lệnh có chức năng: thay đổi giá trị Text của 1 button (giá trị này được lấy ra từ mảng), hiện thị nó ra màn hình khoảng 1s, sau đó tiếp tục thay đổi Text cuả nó và hiện thị cho đến khi hết mảng.
mình viết thế này:
array<int,1>^ CurrentState;
String^ show;
CurrentState = gcnew array<int,1> (9) {1,2,3,4,5,6,7,8,0};
show = " 12345678";
void print_button()
{
this->button1->Text = show->Substring(CurrentState[0],1);
this->button2->Text = show->Substring(CurrentState[1],1);
this->button3->Text = show->Substring(CurrentState[2],1);
this->button4->Text = show->Substring(CurrentState[3],1);
this->button5->Text = show->Substring(CurrentState[4],1);
this->button6->Text = show->Substring(CurrentState[5],1);
this->button7->Text = show->Substring(CurrentState[6],1);
this->button8->Text = show->Substring(CurrentState[7],1);
this->button9->Text = show->Substring(CurrentState[8],1);
}
for(int i=0; i<n; i++)
{
transNum(Answer[i]); //chuyển số answer[i] thành mảng CurrentState
print_button();
Sleep(1000);
}
kết quả thì chương trình có delay, nhưng các button không thay đổi text của nó, chỉ khi kết thúc vòng lặp nó mới hiển thị text được thay đổi bởi giá trị cuối cùng trong mảng.
mình đã thử thay đoạn Sleep(1000) bằng MessageBox::Show() thì tại mỗi bước lặp, khi message box hiện lên thì text của các button quả thực có thay đổi ứng với giá trị trong mảng answer.
bạn nào rõ vụ này xin chỉ giáo.
mình viết thế này:
array<int,1>^ CurrentState;
String^ show;
CurrentState = gcnew array<int,1> (9) {1,2,3,4,5,6,7,8,0};
show = " 12345678";
void print_button()
{
this->button1->Text = show->Substring(CurrentState[0],1);
this->button2->Text = show->Substring(CurrentState[1],1);
this->button3->Text = show->Substring(CurrentState[2],1);
this->button4->Text = show->Substring(CurrentState[3],1);
this->button5->Text = show->Substring(CurrentState[4],1);
this->button6->Text = show->Substring(CurrentState[5],1);
this->button7->Text = show->Substring(CurrentState[6],1);
this->button8->Text = show->Substring(CurrentState[7],1);
this->button9->Text = show->Substring(CurrentState[8],1);
}
for(int i=0; i<n; i++)
{
transNum(Answer[i]); //chuyển số answer[i] thành mảng CurrentState
print_button();
Sleep(1000);
}
kết quả thì chương trình có delay, nhưng các button không thay đổi text của nó, chỉ khi kết thúc vòng lặp nó mới hiển thị text được thay đổi bởi giá trị cuối cùng trong mảng.
mình đã thử thay đoạn Sleep(1000) bằng MessageBox::Show() thì tại mỗi bước lặp, khi message box hiện lên thì text của các button quả thực có thay đổi ứng với giá trị trong mảng answer.
bạn nào rõ vụ này xin chỉ giáo.
Comment