鼠标移动问题(100分)

  • 主题发起人 主题发起人 咩咩
  • 开始时间 开始时间

咩咩

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠,小弟是菜鸟一只,请问怎么样实现鼠标能够缓慢地从某一个按钮到另一个按钮的移动(要求有一个动画地效果)?
 
自己控制鼠标移动速度和位置就可以了
 
重载MOUSEMOVE函数
 
能给出具体的代码吗?
 
呵呵,不好意思,要求是自动地移动过去
 
mouse_event
 
var
pt: TPoint;
begin
pt:= GroupBox1.ClientToScreen( Point( 4,4 ));
SetCursorPos( pt.x, pt.y );
end;
我是这样写的,可是这样的话,鼠标喀嚓一下就过去了啊!
在线等待,高手快帮忙呀!
 
用个Timer慢慢移就是了。
 
:(
没有哪位能直接给出代码嘛?
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
Button2: TButton;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
OldPt, NewPt: TPoint;

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if OldPt.x < NewPt.x then OldPt.x := OldPt.x + 1
else if OldPt.x > NewPt.x then OldPt.x := OldPt.x - 1;

if OldPt.y < NewPt.y then OldPt.y := OldPt.y + 1
else if OldPt.y > NewPt.y then OldPt.y := OldPt.y - 1;

SetCursorPos( OldPt.x, OldPt.y );

if (OldPt.x = NewPt.x) and (OldPt.y = NewPt.y) then Timer1.Enabled := false;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
GetCursorPos(OldPt);
NewPt:= Button2.ClientToScreen( Point( 4,4 ));
Timer1.Enabled := true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled := false;
Timer1.Interval := 10;
end;

end.
 
接受答案了.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部