?
Solved

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

Posted on 2011-03-13
2
Medium Priority
?
1,078 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Make the most of your online learning experience.
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 …
Starting up a Project
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

764 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