Page 1 of 1

Printing a chart into a DC

Posted: Sat Oct 29, 2005 2:09 pm
by 8438208
I have a printing tool, that issues a callback when a user drawn object has to be drawn. One of these parameters is a HCD (handle to device context). Now my question:
How can I attach TeeChart to a specific Device Context or is there another possibility to do an output of a chart into a DC?

Posted: Tue Nov 08, 2005 11:18 pm
by 9637193
Hello,
Here's an example that prints a TeeChart to a Form using the Form handle:

Code: Select all

procedure TForm1.PrintToHandle(DC: HDC; Left, Top, Right, Bottom: Integer);
var tmp:TCanvas;
SaveIndex: Integer;
begin
  tmp:=TCanvas.Create;
  SaveIndex:=SaveDC(DC);
  tmp.Handle:=DC;
  Chart1.PrintPartialCanvas(tmp,Rect(Left,Top,Right,Bottom));
  tmp.Free;
  RestoreDC(DC, SaveIndex);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  PrintToHandle(Form1.Canvas.Handle,0,0,Chart1.Width,Chart1.Height);
end;
Regards,
Marc Meumann