Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move image

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How can I move Image Slowly?
I use:
Xx is coordinates of image mouse move.
Repeat
Image1.Left:=Image1.Left+1;
until Image1.Left=Xx;

but image won't move it just dissapeared in its coordinates and its rise in Xx coordinate
 
Try after the +1 Application.ProcessMessages; or call directly the repaint. And if you want to move the image slowly, you should use Sleep(xxx); (msec) inside the cycle.

Bye, Otto.
 
To actually do this correctly you must use a timer event based on the system clock. I have written a function that will move any component from where it is to an ending TRect. You define the ending TRect (where you want the component to move to) and this function will move it to that location. The following code is below:

{******************************************************************************************************}
//BDP - This function will slide a visual control anywhere on the screen. Just pass in the ending
//rectangle as to where the control will finally end up and the slide interval.
//The slide interval is in milliseconds. It is how slow or fast the control will slide.
procedure p_SlideControl(aControl: TWinControl; arcEnd: TRect; aSlideInterval: Integer);
var
rcStart: TRect;
dwTimeStart, dwTimeEnd, dwTime : DWORD;
x, y, w, h : Integer;

begin
// Get the current controls position
with aControl do begin
rcStart.Left := Left;
rcStart.Bottom := Top + Height;
rcStart.Top := Top;
rcStart.Right := Left + Width;
end;

if ((rcStart.Left <> arcEnd.Left) or
(rcStart.Top <> arcEnd.Top) or
(rcStart.Right <> arcEnd.Right) or
(rcStart.Bottom <> arcEnd.Bottom)) then begin

// Get our starting and ending time
dwTimeStart := GetTickCount;
dwTimeEnd := dwTimeStart + aSlideInterval;
dwTime := dwTimeStart;
while (dwTime < dwTimeEnd) do begin
// While we are still sliding, calculate our new position
x := rcStart.Left - (rcStart.Left - arcEnd.Left)
* Integer(dwTime - dwTimeStart) div aSlideInterval;

y := rcStart.Top - (rcStart.Top - arcEnd.Top)
* Integer(dwTime - dwTimeStart) div aSlideInterval;

w := (rcStart.Right - rcStart.Left)
- ((rcStart.Right - rcStart.Left) - (arcEnd.Right - arcEnd.Left))
* Integer(dwTime - dwTimeStart) div aSlideInterval;

h := (rcStart.Bottom - rcStart.Top)
- ((rcStart.Bottom - rcStart.Top) - (arcEnd.Bottom - arcEnd.Top))
* Integer(dwTime - dwTimeStart) div aSlideInterval;

// Show the control at its changed position
with aControl do begin
Top := y;
Left := x;
Width := w;
Height := h;
end;
dwTime := GetTickCount;
end;

//because the math may not come out to exactly the point requested
//set it there
with aControl do begin
Top := arcEnd.Top;
Left := arcEnd.Left;
Width := arcEnd.Right - arcEnd.Left;
Height := arcEnd.Top - arcEnd.Bottom;
Update;
end;
end;
end;
{******************************************************************************************************}

Hope this helps.

Brett Parkurst
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top