在TForm2
上,我試圖使TProgressBar
開始於0%,並需要30秒才能達到100%。只要TForm1
的TCheckBox
被選中,TProgressBar
就會開始上升。C++ Builder的TForm2上的ProgressBar
我在谷歌上看過,但是這樣的事情讓我沒有什麼好處。
有什麼建議嗎?
TFORM1
//...
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
void __fastcall TFormOne::MyCheckBoxClick(TObject *Sender)
{
FormTwo->Show();
}
TFORM2
//...
#include "Unit2.h"
#include "Unit1.h"
//...
int MSecond = 0, MyTime = 0;
//---------------------------------------------------------------------------
__fastcall TFormTwo::TFormTwo(TComponent* Owner) : TForm(Owner)
{
ProgressBar->Min = 0;
ProgressBar->Max = 100;
ProgressBar->Position = 0;
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TFormTwo::FormCreate(TObject *Sender)
{
MyTime = GetTickCount();
MSecond = 0;
Timer1->Enabled = false;
ProgressBar->Position = 0;
}
//---------------------------------------------------------------------------
void __fastcall TFormTwo::Timer1Timer(TObject *Sender)
{
MSecond = GetTickCount() - MyTime;
if (MSecond < 30000)
ProgressBar->Position = double Trunc(double(MSecond)/300);
else
{
ProgressBar->Position = 100;
Timer1->Enabled = false;
}
}
而你的問題是......? –
順便說一下,**不要**在C++中使用'OnCreate'事件。這是一個Delphi成語,它會在C++中創建非法行爲。改用構造函數。事實上,你現在在'TFormTwo :: FormCreate()'中的所有代碼都不屬於這個項目開始,所以把它除掉。 –