Private Sub PrintPage(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ImGearPageDisplayPrintToolStripMenuItem.Click
'Load an image
Dim igPage As ImGearPage
Dim localFile As FileStream = New FileStream("test1.tif", FileMode.Open)
Try
igPage = ImGearFileFormats.LoadPage(localFile, 0)
Finally
localFile.Close()
End Try
'Create a new ImGearPageDisplay based upon an ImGearPage.
Dim igPageDisplay As ImGearPageDisplay = New ImGearPageDisplay(igPage)
'Set the current ImGearPageView to use this new display.
ImGearPageView1.Display = igPageDisplay
'Initialize a PrintDialog for the user to select a printer.
Dim document As PrintDocument = New PrintDocument()
Dim printDialog As PrintDialog = New PrintDialog()
Try
printDialog.Document = document
'Set the page range to 1 page.
printDialog.AllowSomePages = True
printDialog.PrinterSettings.MinimumPage = 1
printDialog.PrinterSettings.MaximumPage = 1
printDialog.PrinterSettings.FromPage = 1
printDialog.PrinterSettings.ToPage = 1
If (printDialog.ShowDialog(Me) = DialogResult.OK) Then
'Set a name for the print job.
document.DocumentName = Me.Text
'Define a PrintPage event handler and start printing.
AddHandler document.PrintPage, _
New PrintPageEventHandler(AddressOf HandlePrinting)
document.Print()
End If
Finally
printDialog.Dispose()
document.Dispose()
End Try
End Sub
Private Sub HandlePrinting(ByVal sender As Object, ByVal args As PrintPageEventArgs)
'Clone the current Display for use as a printing display.
Dim igPageDisplayPrinting As ImGearPageDisplay = _
ImGearPageView1.Display.Clone()
igPageDisplayPrinting.Page = ImGearPageView1.Display.Page
'Get the current Zoom settings and disabled fixed zoom.
Dim igZoomInfo As ImGearZoomInfo = _
igPageDisplayPrinting.GetZoomInfo(ImGearPageView1)
igZoomInfo.Horizontal.Fixed = False
igZoomInfo.Vertical.Fixed = False
igPageDisplayPrinting.UpdateZoomFrom(igZoomInfo)
'Disable any background before printing.
igPageDisplayPrinting.Background.Mode = _
ImGearBackgroundModes.NONE
'Print to the Graphics device chosen from the PrintDialog.
igPageDisplayPrinting.Print(args.Graphics)
'Let the PrintDialog know there are no more pages.
args.HasMorePages = False
End Sub