小
小争
Unregistered / Unconfirmed
GUEST, unregistred user!
我随手写的在image中求两点间距离,怎么结果不对呀,大家帮看一看。
另如果控件没有mouseup或mousemove等事件,怎么实现求距离。
procedure Tmainform.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
VAR
s,j:real;
s2,j2:real;
he:real;
begin
case z of
true:
begin
image1.Canvas.MoveTo(x,y);
s:=image1.Canvas.PenPos.x;
j:=image1.Canvas.PenPos.y;
z:=false;
end;
false:
begin
image1.Canvas.LineTo(x,y);
image1.Canvas.MoveTo(x,y);
s2:=image1.Canvas.PenPos.x;
j2:=image1.Canvas.PenPos.y;
he:=sqrt(sqr(s2-s)+sqr(j2-j));
label1.Caption:='the distance is'+inttostr(round(he));
z:=true;
end;
end;
end;
另如果控件没有mouseup或mousemove等事件,怎么实现求距离。
procedure Tmainform.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
VAR
s,j:real;
s2,j2:real;
he:real;
begin
case z of
true:
begin
image1.Canvas.MoveTo(x,y);
s:=image1.Canvas.PenPos.x;
j:=image1.Canvas.PenPos.y;
z:=false;
end;
false:
begin
image1.Canvas.LineTo(x,y);
image1.Canvas.MoveTo(x,y);
s2:=image1.Canvas.PenPos.x;
j2:=image1.Canvas.PenPos.y;
he:=sqrt(sqr(s2-s)+sqr(j2-j));
label1.Caption:='the distance is'+inttostr(round(he));
z:=true;
end;
end;
end;