Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-13
2
Medium Priority
?
1,090 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
A short article about problems I had with the new location API and permissions in Marshmallow
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Introduction to Processes
Suggested Courses

618 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