Board index » delphi » HELP PLEASE - Moving components around the screen.

HELP PLEASE - Moving components around the screen.

I'm desparately in need of some help. I'm writing a project that requires me
to click on components and move them around the screen. There will be a
number of components on the screen. I wish to click on one and be able to
drag it and when I let go of the mouse button it moves to that position.

Thats the easy bit that I've al;ready got to work using this code -

ReleaseCapture()
RetVal:=SendMessage(<handle>,WM_NCLBUTTONDOWN,HTCAPTION,0)

My problem is that I can drop the component on top of other components. What
I need is to be able to prevent it being dropped if it is above another
component.

ANY IDEAS, this is quite urgent.

If you no could you please possibily email directly. I get very little
opportunity to check the newsgroups

Thanks

Chris.

 

Re:HELP PLEASE - Moving components around the screen.


In article <6vm57e$5t...@plug.news.pipex.net>, "Ecke" <e...@dial.pipex.com>
writes:

Quote
>I'm desparately in need of some help. I'm writing a project that requires me
>to click on components and move them around the screen. There will be a
>number of components on the screen. I wish to click on one and be able to
>drag it and when I let go of the mouse button it moves to that position.

>Thats the easy bit that I've al;ready got to work using this code -

>ReleaseCapture()
>RetVal:=SendMessage(<handle>,WM_NCLBUTTONDOWN,HTCAPTION,0)

>My problem is that I can drop the component on top of other components. What
>I need is to be able to prevent it being dropped if it is above another
>component.

>ANY IDEAS, this is quite urgent.

I have seen this for moving components :-

"procedure TForm1.Panel1.MouseDown( Sender: etc... );
const
  SC_DRAGMOVE = $F012;
begin
  ReleaseCapture;
  Panel1.Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
end;

This also drags buttons & other controls."

For finding if an overlap occurs (off top of my head - not tested) :-

You would have to use Win API region functions
Create a region for every control - CreateRectRegion( etc etc
When you start to move a control make a region of all other controls with
CombineRgn( etc etc
( or make a region of all controls, when movement starts take out the moving
control from the combined region)
Check that there is an overlap with RectInRegion( etc etc
Then stop the movement of that control

Alan Lloyd
alangll...@aol.com

Other Threads