【发布时间】:2013-06-28 17:08:11
【问题描述】:
每当单击鼠标左键时,我使用 TCanvas 绘制一条蓝线,并在单击鼠标右键时绘制一条红线。目前,每当我单击图表上的另一条线时。我要做的是清除旧线,然后画一条新线。
下面是一些示例代码。
onClick 事件的代码
procedure TForm2.Chart1ChartClick(Sender: TJvChart; Button: TMouseButton;
Shift: TShiftState; X, Y, ChartValueIndex, ChartPenIndex: Integer;
var ShowHint, HintFirstLineBold: Boolean; HintStrs: TStrings);
begin
if Button = mbLeft then
begin
canvas.pen.color := clblue;
PlotHorizontal(X, Y);
end
else if Button = mbRight then
begin
Canvas.Pen.color := clred;
PlotHorizontal(X, Y);
end
结束;
PlotHorizontal 过程
procedure TForm2.PlotHorizontal(X, Y : integer);
begin
with canvas do
begin
// draw the horizontal line
MoveTo(X, Y);
// without the 4 the line doesn't seem to reach the end of the graph
LineTo(X, Chart1.Options.XStartOffset -4);
MoveTo(X, Y);
LineTo(X, Chart1.Options.XStartOffset +
+ Chart1.Options.Yend);
end;
end;
【问题讨论】:
-
“清除旧线”是指“删除最后绘制的任何颜色的线”,还是“删除最后绘制的该颜色的线”?
-
删除用这种颜色绘制的最后一条线。
-
我认为在应该清除的线条上画一条背景颜色的线条就可以了。不过,您必须存储必要的坐标才能做到这一点。但这并不难。
标签: delphi delphi-2007