How do I drag the report into ppviewer?

advertisements

Anyone know how to drag the report in TppViewer? (Delphi 7) i try to use the dagdrop event and dragover event of ppviewer but failed, anyone can help?

procedure Tfrm1.ppviewer1DragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  inherited;
  Accept := Source IS TppViewer;
end;

procedure Tfrm1.ppviewer1DragDrop(Sender, Source: TObject; X,
  Y: Integer);
begin
  inherited;
  if Source is TppViewer then begin
    TppViewer(Source).Left := X;
    TppViewer(Source).Top := Y;
  end;
end;


This answer assumes that you are trying to scroll in the report, by dragging.

TReportPreviewer is the Form

ReportViewer is the ppViewer

Dragging is a Boolean

SaveX, SaveY are Integer

procedure TReportPreviewer.ReportViewerMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Dragging := true;
  SaveX := X;
  SaveY := Y;
end;

procedure TReportPreviewer.ReportViewerMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
  if Dragging then
  begin
    if ReportViewer.ScrollBox.Visible then
      ReportViewer.ScrollBox.HorzScrollBar.Position := ReportViewer.ScrollBox.HorzScrollBar.Position - (X - SaveX);
    if ReportViewer.ScrollBox.Visible then
      ReportViewer.ScrollBox.VertScrollBar.Position := ReportViewer.ScrollBox.VertScrollBar.Position - (Y - SaveY);
    SaveX := X;
    SaveY := Y;
  end;
end;

procedure TReportPreviewer.ReportViewerMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Dragging := false;
end;

I tried using ScrollBy instead of moving the scrollbar position, but it seemed to reset for some reason.