Question
How to use the PrintWithGrid method in Delphi 7 to print the Gantt Chart to a BmpFile or JPeg File ?
Answer
When you send the print to the printer you do like this:
Printer.BeginDoc;
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;
And the only difference when generating an image send in a different device context (hdc).
So go like this to create a bitmap:
Result := TBitmap.Create;
Result.Canvas.Lock;
try
Result.PixelFormat := pf32bit;
Result.Width := xWidth;
Result.Height := xHeight;
TphPrintGantt.PrintWithGrid(G1,Result.Canvas.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);
finally
Result.Canvas.UnLock;
Result.Free;
end;