Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 22nd, 2013, 09:05 AM
tandy tandy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 2 tandy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 42 sec
Reputation Power: 0
Moving an image over a control while staying in the forground at runtime

My application lets the user move an image anywhere on the forum.
The move is triggered by a mousedown event and processed by
the mousemove event of the timage being moved. It basically
just follows the cursor by adding x and y values to Left and top
of the image giving the appearance that the image is being dragged and follows the cursor. All is well with this until the image
comes in contact with a control such as a tbutton or a tlistbox.

When this occurs the image "Disappears" behind the control.
"Send to back" has no effect on the scenario. Is there a
method or procedure that can enable the move object(timage) to
remain visible as it is moved over a control ?

Note1: "Send to back" works if I wish to move one control
over another control, but not with an Image over a control.

Note2: If the situation is changed to implementing the move using Dragging, the Drag Object will stay in the foreround during
the process. However this is not a desirable solution as the behavior is different between situations. In moving the object it will stay "Solid" as it is being moved. The drag creates a transparent image in all methods i have tried. I want the solid.

When dragging the DragObject it can be "dragged off" the form and
if released there is no event triggered. In moving the object the image can not be moved off of the form so it is guaranteed
to have an event triggered at some point (Mouse up eventually)

Any ideas would be appreciated. It seemed like such a trivial thing when i started looking at this a few days ago now its a
seems its a bit more complex Thanks

Gil MacDougall

Reply With Quote
  #2  
Old March 22nd, 2013, 09:35 AM
majlumbo majlumbo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 254 majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 23 h 55 m 14 sec
Reputation Power: 5
I haven't tried this but possibly if you put the image component on a panel (set the image align property to alclient) then move the panel via the same logic as you did for the image.

Reply With Quote
  #3  
Old March 22nd, 2013, 12:03 PM
tandy tandy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 2 tandy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 42 sec
Reputation Power: 0
Great Idea majlumbo !

Quote:
Originally Posted by majlumbo
I haven't tried this but possibly if you put the image component on a panel (set the image align property to alclient) then move the panel via the same logic as you did for the image.


I tried the Tpanel suggestion and it worked ! Thanks! I will
have to recode parts of my application to reference tpanel
but it should work. I really never thought about this behavior
until after i had wrote code involving the images.

For anyone following this thread the solution for moving of the image object was tweaked on by majlumba(kudos).

In most code you find for moving controls the process makes
use of a handle to move the object. I knew i could not use a
handle for an image as it has none. So i implemented a procedure
that just moved the object with x and y from the mousemove
(as i stated in question) It did not dawn on me until majlumbos idea about the panel that using a handle was possible if the image is embedded in a control such as a panel. I went back and placed my image on a panel then the "normal" code used to move objects could be used to move the panel with the image.

Summary:

{code in TPanel was derived from this
as a new memeber i can not paste url so here is code
it uses a button and a radio group to toggle drag on and off
in my case the button code was used as the panel code}

private
{ Private declarations }
public
{ Public declarations }

OldPos: TPoint;
end;

//****************
type
TForm1 = class(TForm)
...
private
{ Private declarations }
Dragged: Boolean;
OldPos: TPoint;
...

procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if RadioGroup1.ItemIndex=0 then
begin
Dragged:=True;
GetCursorPos(OldPos);
SetCapture(Button1.Handle);
end;
end;

procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
NewPos: TPoint;
begin
if Dragged then
with Button1 do
begin
GetCursorPos(NewPos);
Left:=Left-OldPos.X+NewPos.X;
Top:=Top-OldPos.Y+NewPos.Y;
OldPos:=NewPos;
end;
end;

procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Dragged then
begin
ReleaseCapture;
Dragged:=False;
end;
end;
//******************

Paste image on panel
set panel properties:

border :none
height := image.height
width := image.width

image properties:
align = none
left = 0
top = 0

assign the MouseDown,MouseMove,MouseUp events
of the TIMAGE to use the corresponding events of
the Tpanel(that actually has the code).

Set Doublebuffering := true in form create to reduce flickering.

Thanks again majlumbo !

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Moving an image over a control while staying in the forground at runtime

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap