首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi。当鼠标移动时,怎么获得屏幕当前的鼠标的坐标。

2013-01-01 
delphi。。当鼠标移动时,如何获得屏幕当前的鼠标的坐标。。。楼主: 我建了一个form,然后在form的onmosemove事件

delphi。。当鼠标移动时,如何获得屏幕当前的鼠标的坐标。。。
楼主: 我建了一个form,然后在form的onmosemove事件用GetCursorPos这个函数来获取鼠标当前坐标,但只有当鼠标在from窗体内时才能相应这个事件,而我要的是屏幕上任意一点的坐标,哪位高手帮忙指点指点。。。。 
[解决办法]
新建工程、双击窗体、用下列代码覆盖你的unit1:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure TimerTimer(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
var Timer:TTimer;

procedure TForm1.TimerTimer(Sender: TObject);
var pt:TPoint;
begin
  GetCursorPos(pt);
  Caption:='X坐标: '+inttostr(pt.X)+'   Y坐标:  '+inttostr(pt.Y);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer:=TTimer.Create(self);
  with Timer do begin
    Interval:=10;
    Timer.OnTimer:=TimerTimer;
  end;
end;

end.

[解决办法]
procedure TForm1.Timer1Timer(Sender: TObject);
var  p:TPoint;
begin
  GetCursorPos(p);
  memo1.Lines.Add(IntToStr(p.X)+':'+IntToStr(p.Y));
end;

[解决办法]
procedure TForm1.Timer1Timer(Sender: TObject);
var  p:TPoint;
begin
  GetCursorPos(p);
  memo1.Lines.Add(IntToStr(p.X)+':'+IntToStr(p.Y));
end;

[解决办法]
引用:
procedure TForm1.Timer1Timer(Sender: TObject);
var  p:TPoint;
begin
  GetCursorPos(p);
  memo1.Lines.Add(IntToStr(p.X)+':'+IntToStr(p.Y));
end;


用Timer

热点排行