新手问题
大家好想请教下,我想实现个当程序一分钟内没有人点Form就跳个新的Form,如果有人点击过就不触发新的Form;
void __fastcall TForm1::tmr1Timer(TObject *Sender){ TForm2 *form2=new TForm2(this); form2->ShowModal(); delete form2;}//---------------------------------------void __fastcall TForm1::FormCreate(TObject *Sender){ tmr1->Interval=60000; tmr1->Enabled=true;}//---------------------------------------void __fastcall TForm1::FormClick(TObject *Sender){ tmr1->Enabled=false;}
void __fastcall TForm1::tmr1Timer(TObject *Sender){tmr1->Enabled=false; TForm2 *form2=new TForm2(this); form2->ShowModal(); delete form2;tmr1->Enabled=true;}
[解决办法]
测试了可以实现
//---------------------------------------#include <vcl.h>#pragma hdrstop#include "Unit1.h"//---------------------------------------#pragma package(smart_init)#pragma resource "*.dfm"TForm1 *Form1;TDateTime dt;//---------------------------------------__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){}//---------------------------------------void __fastcall TForm1::Timer1Timer(TObject *Sender){ if((double)(Now()-dt)>=1.0/(24*60)) { TForm *f=new TForm(this); f->Show() ; }}//---------------------------------------void __fastcall TForm1::FormCreate(TObject *Sender){ Timer1->Interval=1000; dt=Now();}//---------------------------------------void __fastcall TForm1::FormClick(TObject *Sender){ dt=Now();}//---------------------------------------