【问题标题】:Clear lines drawn with TCanvas使用 TCanvas 绘制的清晰线条
【发布时间】: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

结束;

PlotHorizo​​ntal 过程

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


【解决方案1】:

通过保存绘制线条的旧 X 和 Y 值,我能够让它工作。然后当再次单击鼠标时,我刷新了图表,并再次重新绘制了线条。

【讨论】:

    猜你喜欢
    • 2015-12-12
    • 1970-01-01
    • 2013-07-07
    • 2017-06-06
    • 1970-01-01
    • 1970-01-01
    • 2010-12-21
    • 1970-01-01
    • 2012-08-06
    相关资源
    最近更新 更多