Basic Print Events

All print controller implementations rely on the print document's print events to gather the drawing commands into the Graphics object, either to spool to the printer or to show on the screen:

Sub printDocument1_PrintPage(sender As Object, e As PrintPageEventArgs)
  ' Draw onto the e.Graphics object
  Dim g As Graphics = e.Graphics
  Dim myfont As Font = New Font("Lucida Console", 72)
  g.DrawString("Hello," & vbCrLf & "Printer", myfont, ...)
  myfont.Dispose()
End Sub

Notice that this sample PrintPage event handler creates a font only for printing. For a single page, this code is fine, because it creates the font and then reclaims the font resources when the printing in complete. However, if we're printing more than one page, it's ...

Get Windows Forms Programming in Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.