在C++Builder 6中拖放图像

Drag and drop images in C++ Builder 6

本文关键字:拖放 图像 C++Builder      更新时间:2023-10-16

我正在制作一个益智程序,现在我如何使用导航键移动图片部分,但我如何使用鼠标做到这一点?

我试过使用这个,但图片表现得像疯狂的

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

有什么帮助吗?

编辑:

我把这个放在计时器中,但图像开始同时在两个地方闪烁。。。

    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;

我已经解决了我的问题。

我在OnMouseDown事件中做到了这一点:

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

这个在Timer:上

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