知/Delphi

마우스 움직이는 범위를 패널 안으로 제약하기

채수욱 2012. 5. 3. 18:08

// 패널을 클릭할 때 작동하게. 전역 변수로 bSet:Boolean; 선언

 

procedure TForm1.Panel1Click(Sender: TObject);

var
  MouseRect : TRect;
  pMouse : TPoint;
begin
  if(not bSet) then
  begin
    MouseRect := TPanel(Sender).ClientRect;
    pMouse := point( MouseRect.Left, MouseRect.Top );
    pMouse := TPanel(Sender).ClientToScreen( pMouse );
    OffsetRect( MouseRect, pMouse.X, pMouse.Y );
    ClipCursor( @MouseRect );
  end else
  begin
    ClipCursor(nil);
  end;
  bSet := not bSet;
end;