如何連續執行 MouseDown |
尚未結案
|
firewing
一般會員 發表:23 回覆:47 積分:19 註冊:2002-12-13 發送簡訊給我 |
|
gemi0305
版主 發表:81 回覆:564 積分:629 註冊:2003-05-11 發送簡訊給我 |
參考以下範例,
在form上放一個label、一個timer,加以下的code,
只要在label上一直按著mouse,數字就會一直加,
放開就停了~
同理應用:把你要連續做的程式放在Timer1Timer()裡,就可以做出你要的功能
bool MouseKeepDown=false; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Label1->Caption="0"; Timer1->Interval=100; } //--------------------------------------------------------------------------- void __fastcall TForm1::Label1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { MouseKeepDown=true; } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { if(MouseKeepDown) Label1->Caption = IntToStr(Label1->Caption.ToInt() 1); } //--------------------------------------------------------------------------- void __fastcall TForm1::Label1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { MouseKeepDown=false; }國泰平安 |
gemi0305
版主 發表:81 回覆:564 積分:629 註冊:2003-05-11 發送簡訊給我 |
再試試看加強版的,
左鍵加,右鍵減:
bool MouseKeepDown=false; int MouseButton=0; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Label1->Caption="0"; Timer1->Interval=100; } //--------------------------------------------------------------------------- void __fastcall TForm1::Label1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { MouseKeepDown=true; MouseButton = Button; } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { if (MouseKeepDown) switch (MouseButton) { case mbLeft : Label1->Caption = IntToStr(Label1->Caption.ToInt() 1); break; case mbRight : Label1->Caption = IntToStr(Label1->Caption.ToInt()-1); break; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Label1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { MouseKeepDown=false; }國泰平安 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |