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;
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