Page 1 of 1

Draw horizontal line with DrawLine tool

Posted: Mon Mar 20, 2006 4:13 pm
by 4207556
Is it possible to draw an horizontal line with drawline?

I've tried the ondrawline event and set the toPoint.Y := FromPoint.Y, but then I get rumble during the dragging. A redraw isn't the solution too.

I'm using D7 + Tchart 7

ps. I want to use the right mouse button to drag a line.

Posted: Mon Mar 20, 2006 5:39 pm
by narcis
Hi Arnold D,

You can easily do that custom drawin on TChart's canvas doing something like this:

Code: Select all

var
  Form1: TForm1;
  X0,Y0,X1,Y1: Integer;
  Down: boolean;

implementation

{$R *.dfm}

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (Button=mbRight) then
  begin
    X0:=X;
    Y0:=Y;
    Down:=true;
  end;
end;

procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (Button=mbRight) then
  begin
    X1:=X;
    Y1:=Y;
    Down:=false;
    Chart1.Draw;
  end;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  With Chart1.Canvas do
  begin
    MoveTo(X0,Y0);
    LineTo(X1,Y0);
  end;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if Down then
  begin
    X1:=X;
    Y1:=Y;

    Chart1.Draw;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Down:=false;
end;

Posted: Tue Mar 21, 2006 7:36 am
by 4207556
Thanks!