测试通过,没问题。<br>测试方法:在form上放一个足够大的image,托动鼠标划线测试。<br><br>设置变量:<br>var<br> x1,y1,x2,y2,x3,y3,x4,y4:integer;<br> isMove:boolean;<br><br>procedure TForm1.FormShow(Sender: TObject);<br>begin<br> x1:=400;<br> y1:=30;<br> x2:=30;<br> y2:=400;<br> Image1.Canvas.Pen.Color:=clRed;<br> Image1.Canvas.MoveTo(x1, y1);<br> Image1.Canvas.LineTo(x2, y2);<br>end;<br><br>procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;<br> Shift: TShiftState; X, Y: Integer);<br>begin<br> x3:=X; y3:=Y; x4:=X; y4:=Y;<br> isMove:=true;<br>end;<br><br>procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,<br> Y: Integer);<br>begin<br> if isMove then<br> begin<br> Canvas.Pen.Color:= clRed;<br> Canvas.Pen.Mode := pmNotXor;<br> Canvas.MoveTo(x3, y3);<br> Canvas.LineTo(x4, y4);<br> Canvas.MoveTo(x3, y3);<br> Canvas.LineTo(X, Y);<br> x4:=X; y4:=Y;<br> Canvas.Pen.Mode := pmCopy;<br> end;<br>end;<br><br>procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;<br> Shift: TShiftState; X, Y: Integer);<br>var<br> tmpX: integer;<br>begin<br> if isMove then<br> begin<br> isMove:=false;<br> tmpX:=(y2-y1)*(x4-x3)-(y4-y3)*(x2-x1);<br> if (x<>0) then<br> begin<br> tmpX:=((x2-x1)*(x4*y3-x3*y4)-(x4-x3)*(x2*y1-x1*y2)) div tmpX;<br> y1:=x1; y2:=x2; y3:=x3; y4:=x4;<br> if x1>x2 then<br> begin<br> y1:=x2; y2:=x1;<br> end;<br> if x3>x4 then<br> begin<br> y3:=x4; y4:=x3;<br> end;<br> if InRange(tmpX, y1, y2) and InRange(tmpX, y3, y4) then<br> ShowMessage('相交');<br> end;<br> end;<br>end;<br>