1

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;
Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
killermannnnn
  • 73
  • 1
  • 7
  • 2
    Wow! Is there any living programmer who still knows what C++ Builder 6 is? – Ivan Aksamentov - Drop Sep 02 '14 at 14:27
  • And sorry for offtopic, it will not help you to solve this exact problem, but in 2014, it would probably be a much more reasonable to stop using C++ Builder and look at something like [Qt](http://qt-project.org/). Hope you are not restricted to use Borland's dinosaurs tools. – Ivan Aksamentov - Drop Sep 02 '14 at 14:33
  • i've just started learning programming 3 moths ago :) – killermannnnn Sep 02 '14 at 14:38
  • 1
    Oh, then I feel obliged to tell you about all the modern options. Basically they are listed here: [click](http://en.wikipedia.org/wiki/List_of_widget_toolkits#Based_on_C.2B.2B_.28including_bindings_to_other_languages.29). And here you can find [Best C++ IDE or Editor for Windows](http://stackoverflow.com/questions/89275/best-c-ide-or-editor-for-windows). Qt is a good start for beginning GUI programming, it has extensive documentation, uncountable tutorials and samples and has a good IDE, written in Qt itself. And it's all for free! Unfortunately, it won't solve original problem as it is now. – Ivan Aksamentov - Drop Sep 02 '14 at 14:44
  • 1
    @Drop: I still use C++Builder 6 in my day job. – Remy Lebeau Sep 02 '14 at 20:07
  • @killermannnnn: please provide a [SSCCE](http://sscce.org) that shows where and how you are using the code you have shown. As it stands, it is incomplete. I will say this, though - `Mouse->CursorPos` is expressed in absolute screen coordinates, whereas a control's `Left` and `Top` properties are expressed in client coordinates that are relative to the client area of the control's `Parent` control. You need to take that into account, such as by calling the `Image1->Parent->ScreenToClient()` method. – Remy Lebeau Sep 02 '14 at 20:11
  • @Drop Yes, certainly – M.M Sep 07 '14 at 20:22

1 Answers1

0

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;
killermannnnn
  • 73
  • 1
  • 7
  • You don't need a timer or `Mouse->CursorPos`. You can use the `TImage::OnMouse(Down/Move/Up)` events instead. They provide you with everything you need. – Remy Lebeau Sep 08 '14 at 06:16