在TForm2上,我试图制作一个从0%开始,到100%需要30秒的TProgressBar。TProgressBar一检查TCheckBox of TForm1就会开始上升。
我看过谷歌,但这并没有给我带来什么好处。
有什么建议吗?
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;
}
}发布于 2015-08-15 23:19:08
您没有正确地实现TFormTwo以实现您想要完成的任务。它应该看起来更像这样:
class TFormTwo : class(TFormTwo)
{
__published:
TProgressBar *ProgressBar;
TTimer *Timer1;
//...
void __fastcall FormShow(TObject *Sender);
void __fastcall FormHide(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall Timer1Timer(TObject *Sender);
//...
private:
DWORD StartTime;
//...
public:
__fastcall TFormTwo(TComponent* Owner);
};
__fastcall TFormTwo::TFormTwo(TComponent* Owner)
: TForm(Owner)
{
// you should set these at design-time instead
ProgressBar->Min = 0;
ProgressBar->Max = 100;
}
//---------------------------------------------------------------------------
void __fastcall TFormTwo::FormShow(TObject *Sender)
{
ProgressBar->Position = 0;
StartTime = GetTickCount();
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TFormTwo::FormHide(TObject *Sender)
{
Timer1->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TFormTwo::FormClose(TObject *Sender, TCloseAction &Action)
{
Timer1->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TFormTwo::Timer1Timer(TObject *Sender)
{
DWORD MSecond = GetTickCount() - StartTime;
if (MSecond < 30000)
ProgressBar->Position = int((double(MSecond) / 30000.0) * 100.0);
else
{
ProgressBar->Position = 100;
Timer1->Enabled = false;
}
}https://stackoverflow.com/questions/32028504
复制相似问题