Solved

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

Posted on 2011-03-13
2
1,043 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
ID: 35125036
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
ID: 35125472
That works out well, thank you very much.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 79
Advice in Xamarin 21 78
Delphi: barcode reading on android platform 1 26
Help Required 3 90
A short article about a problem I had getting the GPS LocationListener working.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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 …

813 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

16 Experts available now in Live!

Get 1:1 Help Now