用鼠标点击来画这个多边形,就是通过在imagemousedown、imagemousemove、imagemouseup中输入代码的方式。

解决方案 »

  1.   

    具体是几边形的不限制,就要那种手动的在image上画的方式
      

  2.   

    在鼠标单击的过程中,保存单击位置,将所有的TPoint 组成一个数组,然后调用Canvas.polygon方法就可以
      

  3.   

    //给你一个范例吧!保解决你的问题!!!还有就是,我没加入“橡皮筋”
    //技术,但是那也是很好做的,你自己试试吧!!不会的话,你再问我!
    //还有就是,解决了,可要给我加分啊!!!哈哈哈
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
      TForm1 = class(TForm)
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
      headPoint:Array of Tpoint;//声明一个保存多边形顶点的动态数组
      pointcount:integer=1;//顶点的个数
      _end:boolean=false;  //是否停止绘制多边形
    implementation{$R *.DFM}procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
    if _end=false   then
        begin
            
            if button=mbleft   then//是否是鼠标左键按下
            begin
                SetLength(headpoint,pointcount);//动态分配数组的大小
                headpoint[pointcount-1]:=point(x,y);
                if pointcount=1 then //移动画笔的初始点
                    canvas.MoveTo(headpoint[0].x,headpoint[0].y)
                else
                    canvas.MoveTo(headpoint[pointcount-2].x,headpoint[pointcount-2].y);
                canvas.Pen.Color:=clred;//画笔颜色
                canvas.LineTo(x,y); //绘制直线
                inc(pointcount);     //增加顶点个数
            end
            else    begin //右键按下
                headpoint[pointcount]:=headpoint[0];//形成封闭的多边形
                canvas.Polyline(headpoint);//绘制边线
                canvas.Polygon(headpoint); //填充多边形
                _end:=true;//停止绘制
            end;
        end;
    end;end.
      

  4.   

    http://www.codeidea.com
    中有TPolyline!
      

  5.   

    to  HOOK_TTG(钩子[TTG]) 
     谢谢你的范例,分没问题,我待会给你。
     但我不大知道橡皮筋”技术的原理,能否告诉我?
      

  6.   

    to  HOOK_TTG(钩子[TTG])也给我一个
    [email protected]
      

  7.   

    //这个就是我说的那个“橡皮筋”技术。这个技术可以让用户很方便的看到操作的
    //情况,以便让用户决定下一步的操作。是不是很人性化??
    //这只是个范例,你可以自己扩展……
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
      TForm1 = class(TForm)
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
      headPoint:Array of Tpoint;//声明一个保存多边形顶点的动态数组
      pointcount:integer=1;//顶点的个数
      _end:boolean=false;  //是否停止绘制多边形
    implementation{$R *.DFM}
    var
        head_pos,tail_pos:Tpoint;
        drawing:Boolean;
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
    if _end=false   then
        begin
            SetLength(headpoint,pointcount);//动态分配数组的大小
            headpoint[pointcount-1]:=point(x,y);
            head_pos:=point(x,y); //初始化时,将直线的起点终点赋为同一点
            tail_pos:=head_pos;
            inc(pointcount);//增加顶点个数
            if button=mbleft   then//是否是鼠标左键按下
                drawing:=true
            else    begin //右键按下
                headpoint[pointcount]:=headpoint[0];//形成封闭的多边形
                canvas.Polyline(headpoint);//绘制边线
                canvas.Polygon(headpoint); //填充多边形
                _end:=true;//停止绘制
                drawing:=false;
            end;
        end;
    end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
        if  Drawing=true    then//还在进行绘制吗
        begin
            with    self.canvas do
            begin
                pen.Mode:=pmNot;//设定画笔的模式为反转模式;这样做的目的就是
                                //可以简单快速的擦除前一次画的线
                //画前一次的直线
                MoveTo(head_pos.x,head_pos.y);
                lineto(tail_pos.x,tail_pos.y);
                //画本次的直线
                MoveTo(head_pos.x,head_pos.y);
                lineto(x,y);
                //修正直线终点位置
                tail_pos:=point(x,y);
            end;
        end;
    end;end.