WinAPI: PtInRect - 判断点是否在矩形中

本例效果图:

WinAPI: PtInRect - 判断点是否在矩形中

unit Unit1;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;



type

  TForm1 = class(TForm)

    Button1: TButton;

    procedure FormCreate(Sender: TObject);

    procedure Button1Click(Sender: TObject);

    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);

  end;



var

  Form1: TForm1;



implementation



{$R *.dfm}



var

  R: TRect;



procedure TForm1.FormCreate(Sender: TObject);

begin

  R := Bounds(20, 20, 60, 40);

end;



procedure TForm1.Button1Click(Sender: TObject);

begin

  DrawFocusRect(Canvas.Handle, R);

end;



procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);

const

  Arr: array[Boolean] of string = ('不在矩形中', '在矩形中');

begin

  Text := Arr[PtInRect(R, Point(X,Y))];

end;



end.


 
   

你可能感兴趣的:(api)