Board logo

標題: [Delphi] 鼠標控制 [打印本頁]

作者: admin    時間: 2011-2-13 12:21     標題: [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.

[attach]711[/attach]
作者: wochinaren    時間: 2011-2-26 14:17

看看啊 谢谢




歡迎光臨 How2Do (http://forum.how2do.com.hk/) Powered by Discuz! 7.2