如何才能知道一个点是不是落在某个范围内呢?

cscentaur 2003-10-09 01:15:56
大家都看过在某个画面上的某处点击一下,占击所在的地方的图形就会被选中,但要如何知道点击处所在的点是不是落在这个图形的范围内呢?
...全文
66 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
guolvguolv 2003-10-09
  • 打赏
  • 举报
回复
这个我原来做过,
procedure TMainForm.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (x>118) and (X<218) and (y<400) and (y>292)
then
begin

speedbutton1.Visible:=true;

end
else
if (x>128) and (X<228) and (y<156) and (y>56) then
begin
speedbutton5.Visible:=true;

end
else
if (x>312) and (X<412) and (y<156) and (y>56)
then
begin
speedbutton6.Visible:=true;

end
else
if (x>304) and (X<404) and (y<400) and (y>292) then
begin
speedbutton4.Visible:=true;

end
else
if (x>60) and (X<160) and (y<276) and (y>176) then
begin
speedbutton2.Visible:=true;

end
else if (x>368) and (X<468) and (y<276) and (y>176) then
begin
speedbutton3.Visible:=true;

end
else if (x>450) and (X<520) and (y<385) and (y>344) then
begin
image2.Visible:=true;

end
else
begin
speedbutton1.Visible:=false;
speedbutton2.Visible:=false;
speedbutton3.Visible:=false;
speedbutton4.Visible:=false;
speedbutton5.Visible:=false;
speedbutton6.Visible:=false;
image2.visible:=false;
end;



end;
sundayzhao 2003-10-09
  • 打赏
  • 举报
回复
如果是方形的,那用用PtInRegion(FRgn,x,y) 很方便。

如果形状不确定,那么????????

我觉得还是在画某个图形的时候把这个图形所有的点都保存起来,以后很容易判断,不过浪费空间。

Wally_wu 2003-10-09
  • 打赏
  • 举报
回复
var
pt: point;
begin
getcursorpos(pt);
if (pt.x=???) and (pt.y=???) then
showmessage('yes')
else
showmessage('no')
end;
crossbow 2003-10-09
  • 打赏
  • 举报
回复
很简单呀?

if (Pointer.x > xxx) and (Pointer.y > xxx) and ... then
dickeybird888 2003-10-09
  • 打赏
  • 举报
回复
哈哈----鼠标点
dickeybird888 2003-10-09
  • 打赏
  • 举报
回复
unit Unit1;
interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
FRgn :HRGN;
pt :array [0..3] of TPoint;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
pt[0] :=Point(50,100);
pt[1] :=Point(100,50);
pt[2] :=Point(150,100);
pt[3] :=Point(100,150);
Image1.Canvas.Polygon(pt);
FRgn :=CreatePolygonRgn(pt,4,Winding);
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if PtInRegion(FRgn,x,y) then
showmessage('点在这区域中');
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
DeleteObject(FRgn);
end;

end.
wzds2000 2003-10-09
  • 打赏
  • 举报
回复
关注。。。
帮你顶。。。

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧