Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Moviendo imagenes con el raton (https://www.clubdelphi.com/foros/showthread.php?t=54357)

ZayDun 15-03-2008 19:50:58

Moviendo imagenes con el raton
 
Hola, estoy intentando hacer que una imagen se mueve con el raton, tengo el codigo pero no me termina de convencer ya que la imagen se mueve una vez he soltado el boton del raton, y lo que yo quiero es que la imagen siga al raton hasta que yo lo suelte. aqui dejo el codigo que utilizo por si se le puede agregar algo para mejorarlo o mejor otro metodo. saludos! y gracias.


Código Delphi [-]
procedure TForm1.o10MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var OrgFormPoint, CurCursorPoint, OrgCursorPoint: TPoint;
begin
OrgFormPoint.X := o10.Left;
OrgFormPoint.Y := o10.Top;
GetCursorpos(OrgCursorPoint);
While (GetAsyncKeystate(VK_LBUTTON) <> 0) do
begin
GetCursorpos(CurCursorPoint);
o10.Left := OrgFormPoint.X - OrgCursorPoint.X + CurCursorPoint.X;
o10.Top := OrgFormPoint.Y - OrgCursorPoint.Y + CurCursorPoint.Y;
end;

ixMike 15-03-2008 20:16:35

Lo que pasa es que no mandas dibujar a la imagen hasta que se suelta:

Código Delphi [-]
procedure TForm1.o10MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
 var OrgFormPoint, CurCursorPoint, OrgCursorPoint: TPoint;
begin
 OrgFormPoint.X := o10.Left; 
 OrgFormPoint.Y := o10.Top;
 GetCursorpos(OrgCursorPoint);
 While (GetAsyncKeystate(VK_LBUTTON) <> 0) do
   begin
   GetCursorpos(CurCursorPoint);
   o10.Left := OrgFormPoint.X - OrgCursorPoint.X + CurCursorPoint.X;
   o10.Top := OrgFormPoint.Y - OrgCursorPoint.Y + CurCursorPoint.Y;
   Repaint; //Te falta esta línea
   end;
end;


Salu2 :)


Edito: En vez de redibujar la imagen, has de redibujar todo el Form, ya que sino queda un "rastro".

ZayDun 15-03-2008 20:31:47

gracias ixMike por la ayuda, parpadea un poco.. xD pero eso ya es otra cosa, Salu2

ixMike 15-03-2008 20:36:10

Si, ya lo imaginaba que parpadearía... sería cuestión de redibujar sólo cuando hubiera movimiento, y no cuando estuviera parado ;)

ZayDun 15-03-2008 21:05:31

ya he solucionado el parpadeo, aqui dejo el codigo.. tan solo tenia que poner la propiedad DoubleBuffered del Form a True.

Código Delphi [-]
Form1.DoubleBuffered := true;


La franja horaria es GMT +2. Ahora son las 18:35:04.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi