我的code如下,如果我想要在按下空白鍵即可讓cpu先暫停,再點選一次Button1可重新執行,程式應該怎麼寫比較好? 下面的寫法在按空白鍵後會暫停但點選Button1後會出現很亂的圖,和一開始執行時不同,煩請高手指點,謝謝! p.s.1:我覺的好像是暫停前所遺留的Chart數值和新執行的Chart搞在一起.
p.s.2:1.txt內是100組不同的整數. code: //-------------------------------------------------------
#include
#include
#include
#include
#include
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//-----------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//----------------------------------------------------
ifstream fin;
int t=0;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
fin.open("c:\\1.txt", ios::in);
int i;
for (i=0;i<20;i )
{
Series1->AddY(0,t,clRed);
t=t 1;
}
Timer1->Enabled=true;
Button1->Enabled=false;
}
//---------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
int a2;
fin>>a2;
Chart1->Series[0]->Delete(0);
Chart1->Series[0]->AddXY(t,a2,t,clRed);
t=t 1;
if (t==100)
Timer1->Enabled=false;
}
//--------------------------------------------- void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{
if (Key == 32) //32:空白鍵
{
Timer1->Enabled=false;
fin.close();
t=0;
Button1->Enabled=true;
}
}
//-------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Timer1->Enabled=false;
}
//--------------------------------------------