返回列表 發帖

[Delphi] 鼠標控制

以下例子說明如何控制鼠標位置及如何顯示/隱藏鼠標

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, shellAPI, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button4: TButton;
    Button3: TButton;
procedure SetMousePos(x, y: longint) ;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.SetMousePos(x, y: longint) ;
var pt: TPoint;
begin
    pt := ClientToScreen(point(x, y)) ;
    SetCursorPos(pt.x, pt.y) ;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
SetCursorPos(0,0);    //absolute location
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
SetMousePos(0,0);   //relative location
end;


procedure TForm1.Button4Click(Sender: TObject);
begin
ShowCursor(False);  //hide mouse pointer within this window only, it is not systemwise.

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  ShowCursor(True); //show the mouse pointer
end;


end.

附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊
Bill Tang     MSN:billtang@openplatform.com.hk
Openplatform Technology Co.,Ltd. 資訊坊科技有限公司  
無線工程施工、方案設計、無線產品、天饋材料、終端設備綜合供應商
Tel: 852-27491011  Fax: 852-81483532

看看啊 谢谢
蒲公公

TOP

返回列表