This sample uses VB6 code to show how to call the PrintToHdc method and also react to OnPrintToHdcNewPage event that will allow you to divide your print over as pages that are needed. OnPrintToHdcNewPage will also help you to skip pages and only render a page with a certain page number.
Private Sub CommandPrint_Click()
Dim lngWidthReturned As Long
Dim lngHeightReturned As Long
Dim dblXscale As Double
Dim lngTitleHeight As Long
Dim lngPicWidth As Long
gUsingMultiPagePrint = True
With phGantX1
dblXscale = 3.5
lngPicWidth = picPreview.Width \ Screen.TwipsPerPixelX
Printer.Print “Anything really” ‘ must init printer somehow, ideal is to call StartDoc, but print will also suffice
Call .PrintToHdc(Printer.hDC, 1, lngTitleHeight, dblXscale, dblXscale, .TreeWidth, _
.TopItemTree, -1, False, .Start, .Stop, .GetScaleLen, .ScalerHeight, _
lngWidthReturned, lngHeightReturned)
End With
Printer.EndDoc
End Sub
Private Sub phGantX1_OnPrintToHdcNewPage(ByVal theGant As phGantXControl.IphGantX3, ByVal aPageNo As Long, aPageHeight As Long, aPageWidth As Long, goahead As Boolean, render As Boolean)
If gUsingMultiPagePrint Then
If aPageNo > 1 Then
Printer.NewPage
End If
aPageHeight = 1000 ‘pixels, you will probably want to find out the paper size and use it here
aPageWidth = 1000 ‘pixels
goahead = True ‘ true, continue , false will end this print-run
render = True ‘ true=this page will be drawn, false=this page will not be drawn (good for print of page x)
Else
aPageHeight = -1 ‘no limit
aPageWidth = -1 ‘no limit
goahead = True
render = True
End If
End Sub
————————————–
We got a question on how to go about adapting the print scaling in runtime so that you can use as much of the paper as possible
private void CustDocPrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
Rectangle r=new Rectangle(e.MarginBounds.Location,e.MarginBounds.Size);
// here is check if my columns width are larger that the paper (or preview) width
float neededscaling=((float)e.MarginBounds.Width)/((float)Math.Max(3000,grid.Columns.SumWidth()));
if (neededscaling<1 && neededscaling>0)
{
// Then I scale it...
e.Graphics.ScaleTransform(neededscaling,neededscaling);
// ...and since everything got smaller, I can print a bigger Rectangle...
r= new Rectangle((int)(r.X/neededscaling),(int)(r.Y/neededscaling),(int)(r.Width/neededscaling),(int)(r.Height/neededscaling));
}
grid.PrintPage(e.Graphics,r,ref morep);
e.HasMorePages=morep;
}