大家都看过在某个画面上的某处点击一下,占击所在的地方的图形就会被选中,但要如何知道点击处所在的点是不是落在这个图形的范围内呢?

解决方案 »

  1.   

    unit Unit1;
    interfaceuses
      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.
      

  2.   

    很简单呀?if (Pointer.x > xxx) and (Pointer.y > xxx) and ... then
      

  3.   

    var
      pt: point;
    begin
      getcursorpos(pt);
      if (pt.x=???) and (pt.y=???) then
        showmessage('yes')
      else
        showmessage('no')
    end;
      

  4.   

    如果是方形的,那用用PtInRegion(FRgn,x,y) 很方便。如果形状不确定,那么????????我觉得还是在画某个图形的时候把这个图形所有的点都保存起来,以后很容易判断,不过浪费空间。
      

  5.   

    这个我原来做过,
    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;