Solved

Delphi 7 - How to make a collision detection on a movable panel...

Posted on 2011-03-13
2
1,033 Views
Last Modified: 2012-05-11
Thanks to the other guy in this thread (here) I was able to make a panel movable the way I wanted it, but now I also need it to detect and stop upon collision.

As a sample, I inserted a third panel in the form called panel3, when I hover panel1 into it, I need it to stop, not proceed. In fact, I need it to stop when it hits any edge of the form (no matter what size that is). how can I proceed?

The sample source is attached, thanks.

Edit: As an example of what I mean, if panel1 hits the edge of the form on the left side, it can still move top, bottom and right, as if it was a real wall.
movablepanel.zip
0
Comment
Question by:John86a
2 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
Comment Utility
Please check this out:
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
    if MDown then
    begin
      GetCursorPos(NPnt);
      if (Panel1.Top < Panel3.Height) then
        Panel1.Top := Panel3.Height;
      if (Panel1.Left < 0) then
        Panel1.Left := 0;

      Panel1.Left := Panel1.Left - OPnt.X + NPnt.X;

      if (Panel1.Top + Panel1.Height >= ClientHeight) then
        Panel1.Top := ClientHeight-Panel1.Height;
      if (Panel1.Left + Panel1.Width >= ClientWidth) then
        Panel1.Left := ClientWidth-Panel1.Width;

      Panel1.Top := Panel1.Top - OPnt.Y + NPnt.Y;

      OPnt := NPnt;
    end;
end;

Open in new window

movablepanel-updated.zip
0
 

Author Closing Comment

by:John86a
Comment Utility
That works out well, thank you very much.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about a problem I had getting the GPS LocationListener working.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now