10243 : Printing in VCL

Question

Using the TPhGant-component I would like to print the gantview as well. However the PrintToHDC seems to be available in the ActiveX-version only.

After some experiments with methods such as PrintWithGrid (causing an AV for unknown reasons) and PhGanttPrinting. TphPrintGantt.Print (is printing but timeobjects are missing?) I would like to have an example on how to print the gantview including treeview and timeobjects since there is not one available for the VCL-component (or i might havnt discovered it yet 😉 )

Tnx in advance 4 your help

Answer

There is a sample in the Samples\VCLNative\VCL\MultiPagePrint folder.

Is does this to start the print:

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  usedwidth,
  usedHeight:integer;
begin
  //showmessage(‘I have no idea how to do this ???’);
  //Answer#
  Printer.BeginDoc;
  Printer.Handle;
  TphPrintGantt.PrintWithGrid(G1,Printer.Handle,10,10,2,2,G1.TreeWidth,nil,-1,true,g1.Start,g1.Stop,g1.Width-g1.TreeWidth,g1.ScalerHeight,usedwidth,usedHeight,0,0,nil);
  Printer.EndDoc;
end;

and also has this in the OnPrintToHdcNewPage event:

procedure TForm1.G1PrintToHdcNewPage(theGant: TphGant_ComBasic;
  aPageNo: Integer; var pageHeight, pageWidht: Integer; var goahead,
  render: Boolean);
begin
    //Answer# continued

  pageHeight:=Printer.PageHeight;
  pageWidht:=Printer.PageWidth;
  goahead:=true;
  render:=true;
  if aPageNo>1 then
    Printer.NewPage;

end;

I would guess that your problems is due to that you are not using the grid option. If you are using the tree you can use the TphPrintGantt.Print call instead…

 

Leave a Reply