本例效果图:


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.

posted on 2008-05-23 00:13  万一  阅读(5389)  评论(2编辑  收藏  举报