線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1420
推到 Plurk!
推到 Facebook!

滑鼠「拖曳」控制?

尚未結案
enu
中階會員


發表:36
回覆:93
積分:55
註冊:2003-10-22

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-08-27 14:07:15 IP:163.27.xxx.xxx 未訂閱
各位先進好,小弟請教一個問題:image1可依固定路線移動(如下),現在小弟想要使用image2去控制image1,也就是image1移動一步後,滑鼠必須將image2「拖曳」到image1上面時,image1才繼續進行下一步,直到image1走完。不知道直下來程式應如何修改比較適當?懇請賜教!感謝!    
int path [15][2] = {{11, 104}, {74, 94}, {135, 70}, {181, 83}, {212, 103}, {249, 131}, {287, 160}, {311, 189}, {317, 240}, {316, 273}, {366, 301}, {420, 329}, {467, 353}, {511, 362}, {520, 362}};    for(int i=0;i<15;i  )
 {
 Form1->Image1->Left=path[i][0];
 Form1->Image1->Top =path[i][1];
}  
發表人 - taishyang 於 2004/08/27 14:18:30
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-08-27 23:07:00 IP:211.76.xxx.xxx 未訂閱
enu 您好:
引言: 各位先進好,小弟請教一個問題:image1可依固定路線移動(如下),現在小弟想要使用image2去控制image1,也就是image1移動一步後,滑鼠必須將image2「拖曳」到image1上面時,image1才繼續進行下一步,直到image1走完。不知道直下來程式應如何修改比較適當?懇請賜教!感謝!
int path [15][2] = {{11, 104}, {74, 94}, {135, 70}, {181, 83}, {212, 103}, {249, 131}, {287, 160}, {311, 189}, {317, 240}, {316, 273}, {366, 301}, {420, 329}, {467, 353}, {511, 362}, {520, 362}};    //---------------------------------------------------------------------------
static index = 0;    void MoveImage()
{
 Form1->Image1->Left=path[index][0];
 Form1->Image1->Top =path[index][1];
}    void __fastcall TForm1::Image1DragOver(TObject *Sender, TObject *Source,
      int X, int Y, TDragState State, bool &Accept)
{
  index = (index 1) % 15;  // 產生循環變化
  MoveImage();
}
//---------------------------------------------------------------------------
發表人 - taishyang 於 2004/08/27 14:18:30
試著改寫您的程式碼供您參考,假設您能正確捕捉到image2「拖曳」到image1上面。 RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====#####
enu
中階會員


發表:36
回覆:93
積分:55
註冊:2003-10-22

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-08-30 02:12:57 IP:220.142.xxx.xxx 未訂閱
先謝謝richtop先生;小弟根據您在其它文章中提到的方式去控制image2是可以任意的移動image2,可是問題是image1不動了,是否可以再請教如何來修改呢?感激不儘,謝謝!
int path [15][2] = {{11, 104}, {74, 94}, {135, 70}, {181, 83}, {212, 103}, {249, 131}, {287, 160}, {311, 189}, {317, 240}, {316, 273}, {366, 301}, {420, 329}, {467, 353}, {511, 362}, {520, 362}};    //--------------------------------------------------------------------
static index = 0;    void MoveImage()
{
 Form1->Image1->Left=path[index][0];
 Form1->Image1->Top =path[index][1];
}    void __fastcall TForm1::Image1DragOver(TObject *Sender, TObject *Source,
      int X, int Y, TDragState State, bool &Accept)
{
  index = (index 1) % 15;  // 產生循環變化
  MoveImage();
}
//-------------------------------------------------------------------    int   prevX, prevY;
bool  drawing=false;    void __fastcall TForm1::Image2MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
drawing = true;
   prevX = X;
   prevY = Y;    }
//-------------------------------------------------------------------
void __fastcall TForm1::Image2MouseUp(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
drawing = false;
}
//-------------------------------------------------------------------
void __fastcall TForm1::Image2MouseMove(TObject *Sender, TShiftState Shift,
      int X, int Y)
{
if ( drawing )
    { int dx = X - prevX;
      int dy = Y - prevY;
      Image2->Top   = dy;
      Image2->Left  = dx;
    }
} 
 
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-08-30 11:58:31 IP:211.76.xxx.xxx 未訂閱
enu 您好: 依照您的描述,知道您是希望抓著某一影像再靠近另一個影像,並能驅使另一影像移動。所以先前用的DragOver,好想比較不適用(其實是我沒試出這效果來)。 因此我改採測試兩> > 不知道有沒有其它遺漏,您先試試有問題再討論囉!< > <>< face="Verdana, Arial, Helvetica">引言:
int path [15][2] = {{11, 104}, {74, 94}, {135, 70}, {181, 83}, {212, 103}, {249, 131}, {287, 160}, {311, 189}, {317, 240}, {316, 273}, {366, 301}, {420, 329}, {467, 353}, {511, 362}, {520, 362}};    //--------------------------------------------------------------------
static index = 0;    void MoveImage()
{
 Form1->Image1->Left=path[index][0];
 Form1->Image1->Top =path[index][1];
}
void chekThenMove(TImage *imgMoving, TImage *imgDst)
{ if ( abs(2*(imgMoving->Left - imgDst->Left)) <= (imgMoving->Width imgDst->Width)  &&
       abs(2*(imgMoving->Top  - imgDst->Top )) <= (imgMoving->Height imgDst->Height)    )
    { index = (index 1) % 15;  // 產生循環變化
      MoveImage();
    }
}    //-------------------------------------------------------------------    int   prevX, prevY;
bool  drawing=false;    void __fastcall TForm1::Image2MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
   drawing = true;
   prevX = X;
   prevY = Y;    }
//-------------------------------------------------------------------
void __fastcall TForm1::Image2MouseUp(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
  drawing = false;
}
//-------------------------------------------------------------------
void __fastcall TForm1::Image2MouseMove(TObject *Sender, TShiftState Shift,
      int X, int Y)
{
if ( drawing )
    { int dx = X - prevX;
      int dy = Y - prevY;
      Image2->Top   = dy;
      Image2->Left  = dx;
      chekThenMove(Image2, Image1);
    }
} 
 
RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====#####
enu
中階會員


發表:36
回覆:93
積分:55
註冊:2003-10-22

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-08-30 13:05:52 IP:163.27.xxx.xxx 未訂閱
謝謝richtop先生,但不知道是不是小弟有那裡沒設定好?image2還是拖不動,可否再請教一下?感謝!
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-08-30 15:29:25 IP:211.76.xxx.xxx 未訂閱
enu 您好:
引言: 謝謝richtop先生,但不知道是不是小弟有那裡沒設定好?image2還是拖不動,可否再請教一下?感謝!
我試著重開一個新的Application,在Form1上放入Image1與Image2,並設定所有Image的AutoSize屬性為true,最後分別指定圖檔給它們。 選取Image2,點選其OnMouseDown,OnMouseUp,OnMouseMove事件,最後用上文的程式碼取代這三個事件的程式碼部分,就能執行了。 您先試試看囉!
enu
中階會員


發表:36
回覆:93
積分:55
註冊:2003-10-22

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-08-31 12:50:44 IP:163.27.xxx.xxx 未訂閱
可以拖得動了,謝謝richtop先生;但問題是image2只要一碰到image1,image1就移動到下一步了(不用將image2放在image1上,image1就移動了),跟之前所說的將image2「拖曳」到image1上面才移動有點出入;如果小弟要確認image2拖曳到image1,比如說拖曳到image1上停留一秒鐘,image1才移動到下一步,不知有無先進可提供一些建議!感謝!
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-08-31 21:22:59 IP:211.76.xxx.xxx 未訂閱
enu 您好:    您終於說出內心真正的期待了。 希望這次能把問題解決掉,否則的話,...,就只好繼續想辦法了!。 這次我加入>初設時令>)作為計時與判別圖形是否重疊以便暫停 class="code"> //--------------------------------------------------------------------------- int path [15][2] = {{11, 104}, {74, 94}, {135, 70}, {181, 83}, {212, 103}, {249, 131}, {287, 160}, {311, 189}, {317, 240}, {316, 273}, {366, 301}, {420, 329}, {467, 353}, {511, 362}, {520, 362}}; //-------------------------------------------------------------------- static index = 0; void MoveImage() { Form1->Image1->Left=path[index][0]; Form1->Image1->Top =path[index][1]; Form1->Timer1->Enabled = false; // 如果希望只要還重疊繼續移動Image1,請註解此行。 } void chekThenMove(TImage *imgMoving, TImage *imgDst) { if ( abs(2*(imgMoving->Left - imgDst->Left)) < (imgMoving->Width imgDst->Width) && abs(2*(imgMoving->Top - imgDst->Top )) < (imgMoving->Height imgDst->Height) ) { Form1->Timer1->Enabled = true; } else Form1->Timer1->Enabled = false; } //------------------------------------------------------------------- int prevX, prevY; bool drawing=false; void __fastcall TForm1::Image2MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { drawing = true; prevX = X; prevY = Y; } //------------------------------------------------------------------- void __fastcall TForm1::Image2MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { drawing = false; } //------------------------------------------------------------------- void __fastcall TForm1::Image2MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if ( drawing ) { int dx = X - prevX; int dy = Y - prevY; Image2->Top = dy; Image2->Left = dx; chekThenMove(Image2, Image1); } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormActivate(TObject *Sender) { DoubleBuffered = true; } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { chekThenMove(Image2, Image1); if ( Timer1->Enabled ) { index = (index 1) % 15; // 產生循環變化 MoveImage(); } } //--------------------------------------------------------------------------- RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====##### 發表人 - richtop 於 2004/08/31 21:30:55
enu
中階會員


發表:36
回覆:93
積分:55
註冊:2003-10-22

發送簡訊給我
#9 引用回覆 回覆 發表時間:2004-09-01 00:58:47 IP:220.142.xxx.xxx 未訂閱
再次感謝richtop先生不厭其煩的指導,但可能小弟上回未將問題表達清楚,所以問題仍然沒有解決;從richtop先生提供的方式確實已經可以拖曳image2去控制image1移動到下一步,但是小弟想要解決的問題是image2拖曳到image1上,滑鼠將click放開後,image1才移動到下一步(也就是按住滑鼠左鍵拖曳image2到image1上,放開滑鼠左鍵後image1才移動到下一步);而richtop先生所提供的辦法是只要一直按住滑鼠左鍵拖曳image2去碰觸image1就會讓image1移動。不知道這樣的表達是否能讓先進們更了解小弟的問題?還請各位先進不吝指教!感恩!
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#10 引用回覆 回覆 發表時間:2004-09-01 11:57:01 IP:211.76.xxx.xxx 未訂閱
enu 您好傢伙:    真不知這個工作是誰交辦的,如果是您的"老"字輩(老闆,老師,老婆,老子(您自己)等)上司的話,真該給它....好好做!開開玩笑! 您一下要停一秒,這會又好像不必了,真是令人無法"捉摸"(好像您程式要的功能一樣)! "如果您當真"只要滑鼠放開後,當影像有重疊時才讓 >
enu
中階會員


發表:36
回覆:93
積分:55
註冊:2003-10-22

發送簡訊給我
#11 引用回覆 回覆 發表時間:2004-09-01 13:03:07 IP:163.27.xxx.xxx 未訂閱
哈哈哈!真是不好意思,一直麻煩richtop先生,不過經您後來稍稍修改的程式將問題解決了,可以向"老"字輩的交差了! 感恩感恩!
enu
中階會員


發表:36
回覆:93
積分:55
註冊:2003-10-22

發送簡訊給我
#12 引用回覆 回覆 發表時間:2004-09-01 13:09:19 IP:163.27.xxx.xxx 未訂閱
同樣的類似問題,可否再請教richtop前輩,當然小弟將其開在另一個主題。懇請賜教!謝謝!
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#13 引用回覆 回覆 發表時間:2004-09-01 23:22:13 IP:211.76.xxx.xxx 未訂閱
enu 您好:    
引言: 同樣的類似問題,可否再請教richtop前輩,當然小弟將其開在另一個主題。懇請賜教!謝謝!
總算是功德圓滿了。< > 不過程式有一個小小的 > 如果是我會的東西,歡迎來討論。< >
系統時間:2024-05-14 2:29:59
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!