How to auto-scroll the chart when the user drags an allocation past the edge.


Drop a timer on the form, and attach the following events:

procedure TForm1.RACAllocationDragStart(
    Sender: TObject;
    Resource: TssResource;
    Allocation: TssResourceAllocation;
    var AllowDrag: Boolean);
begin
  Timer1.Interval := 100;
  Timer1.Enabled := true;
end;

procedure TForm1.RACAllocationDragEnd(
    Sender: TObject;
    Resource: TssResource;
    Allocation: TssResourceAllocation);
begin
  Timer1.Enabled := false;
end;

procedure TForm1.RACAllocationDragCancel(
    Sender: TObject;
    Resource: TssResource;
    Allocation: TssResourceAllocation);
begin
  Timer1.Enabled := false;
end;

procedure TForm1.TssRACAllocationSwitchResource(
    Sender: TObject;
    FromResource, ToResource: TssResource;
    Allocation: TssResourceAllocation);
begin
  Timer1.Enabled := false;
end;

// this event handler only fires when an allocation is being dragged
procedure TForm1.Timer1Timer(Sender: TObject);
var
  pt: TPoint;
begin
  with TssRAC do begin
    pt := ScreenToClient(Mouse.CursorPos);

    // scroll horizontally?
    if pt.x < PlotRect.Left then
      ScrollChart(-(EndAt - StartAt) / 25.0)
    else if pt.x > PlotRect.Right then
      ScrollChart((EndAt - StartAt) / 25.0);

    // scroll vertically?
    if pt.y > PlotRect.Bottom then
      FirstDisplayedIndex := FirstDisplayedIndex + 1
    else if pt.y < PlotRect.Top then
      FirstDisplayedIndex := FirstDisplayedIndex - 1;
  end;
end;
What People Say

This is a great component. I've been using it for a year. It's well written, performance is top notch, and the couple of time I've asked for support, I've gotten it right away from the author.
Steve McForest
More …

No malware No spam
McAfee Site Report
Web of Trust