828
社区成员
发帖
与我相关
我的任务
分享
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart, Generics.Collections;
type
TForm1 = class(TForm)
cht1: TChart;
fstlnsrsSeries1: TFastLineSeries;
procedure cht1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure cht1AfterDraw(Sender: TObject);
private
{ Private declarations }
FLst : TList<TPoint>; //存储坐标点
procedure PrintLine(const nStep: Integer); //划线 nStep:划线步长
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FLst.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FLst := TList<TPoint>.Create;
end;
procedure TForm1.PrintLine(const nStep : Integer);
var
i : integer;
pPoint : TPoint;
begin
if nStep < 2 then
Exit;//raise Exception.Create('错误的步长值!');
if FLst.Count < nStep then
exit;
cht1.Canvas.Pen.Color := clRed;
i := FLst.Count - nStep;
while i < FLst.Count - 1 do
begin
pPoint := FLst.Items[i];
cht1.Canvas.MoveTo(pPoint.X, pPoint.Y);
inc(i);
pPoint := FLst.Items[i];
cht1.Canvas.LineTo(pPoint.X, pPoint.Y);
end;
end;
procedure TForm1.cht1AfterDraw(Sender: TObject);
begin
PrintLine(FLst.Count);
end;
procedure TForm1.cht1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
pPoint : TPoint;
begin
//按住Ctrl点击鼠标左键, 记录坐标点
if (ssCtrl in shift) and (Button = mbLeft) then
begin
pPoint.X := x;
pPoint.Y := y;
FLst.Add(pPoint);
PrintLine(2);
end;
end;
end.