看板 C_and_CPP 關於我們 聯絡資訊
給一些小小的建議: 1. 非不得已,請不要使用全域變數 2. 在寫視窗程式時,重覆性的動作不宜使用迴圈 + sleep 容易使得視窗卡死無反應,而應該改用 timer 來周期性的執行 3. 要取得鍵盤的按鍵,也該使用視窗事件,而非 getche() 函式 因此程式碼可以這麼改: Void button1_Click(Object^ sender, EventArgs^ e) { if(!isStart) { isStart=true; this->button1->Text = L"Stop"; this->timer1->Enabled = true; } else { isStart=false; this->button1->Text = L"Start"; this->timer1->Enabled = false; } } /* 在 timer1->Enabled 被設為 true 後,這個函式會被周期性的呼叫 */ Void timer1_Tick(Object^ sender, EventArgs^ e) { Point p = this->pictureBox1->Location; p.X--; this->pictureBox1->Location = p; } 至於怎麼加入一個 timer,怎麼控制它在 enable 之後的發生頻率 就交給你自己去研究一下囉 (畢竟很簡單) 總之,請記得,視窗程式必須寫成「事件驅動」(event driven) 也就是「發生某件事→做某些事」的模式 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.117.171.46 ※ 編輯: james732 來自: 140.117.171.46 (01/06 13:14)
VVll:你真是好人qq 終於看到回應了 01/06 13:57