在delphi中,可以用WIN API锁定鼠标移动范围。

设有两个按钮,button1用来锁定范围,button2用来解除锁定,代码为:

procedure TForm1.Button1Click(Sender: TObject);
var
  btPanel: TRect;
begin
  btPanel := Panel1.BoundsRect; // 限制在Button2的范围
  MapWindowPoints(handle, 0, btPanel, 2); // 座标换算
  ClipCursor(@btPanel); // 限制鼠标移动区域
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
  ClipCursor(nil);
end;

相关文章: