Drag and drop images in C++ Builder 6

不羁的心 提交于 2019-12-08 05:57:28

问题


I'm making a Puzzle program and I now how to move the picture parts with navigation keys but how do I do that using mouse ?

I've tried using this but picture is acting like crazy

Image1->Top=Mouse->CursorPos.x;
Image1->Left=Mouse->CursorPos.y;

Any help?

Edit:

I put this in Timer but Image started blinking in two places at once...

    int difference_x=Form1->Image1->Left - Mouse->CursorPos.x;
    int difference_y=Form1->Image1->Top  - Mouse->CursorPos.y;

    int xxx=Mouse->CursorPos.x - difference_x ;
    int yyy=Mouse->CursorPos.y - 26 - difference_y;
                              // 26 is Cursor height

    Image1->Top=yyy;
    Image1->Left=xxx;

回答1:


I've sold my problem.

I did this in OnMouseDown event:

difference_x=Form1->Image1->Left-Mouse->CursorPos.x;
difference_y=Form1->Image1->Top-Mouse->CursorPos.y;
Timer1->Enabled=true;

and this on Timer:

int xxx=Mouse->CursorPos.x +difference_x ;
int yyy=Mouse->CursorPos.y +difference_y;

Image1->Top=yyy;
Image1->Left=xxx;


来源:https://stackoverflow.com/questions/25625173/drag-and-drop-images-in-c-builder-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!