I managed to solve the problem thanks to the following post:
Thank you very very much Tezzo
First create the following class-variables
Private fileCount As Integer = 0 // Index of the current file/Image
Private currPage As Integer = 0 // Current Page in the current file/Image
Private pCount As Integer = 0 // PageCount in the current file/Image
Private currImage As Image // My Current Image
Create a new PrintDocument (in some function) and assign it to PrintPreviewDialog
Dim vPrintDoc As New PrintDocument
vPrintDoc.DefaultPageSettings.Landscape = False
AddHandler vPrintDoc.PrintPage, AddressOf docPrintPage
AddHandler vPrintDoc.BeginPrint, AddressOf docBeginprint
Dim i As PrintPreviewDialog = New PrintPreviewDialog
i.Document = vPrintDoc
i.ShowDialog()
Inside your method docBeginPrint
you set your classvariables (declared before) to stats of the first (if present)
Private Sub docBeginprint(sender As Object, e As PrintEventArgs)
If fileN.Count > 0 Then
currPage = 0
currImage = Image.FromFile(fileN.Item(0))
pCount = currImage.GetFrameCount(FrameDimension.Page)
End If
End Sub
'Then in your docPrintPage you start printing
Private Sub docPrintPage(sender As Object, e As PrintPageEventArgs)
currImage.SelectActiveFrame(FrameDimension.Page, currPage) 'Set the Active Frame of your image to that of the following frame that needs to printed.
Using st As MemoryStream = New MemoryStream() 'We use a memory stream to print Images in order to avoid a bug inside the e.graphics.
currImage.Save(st, ImageFormat.Bmp)
Dim bmp As Bitmap = CType(Image.FromStream(st), Bitmap)
e.Graphics.DrawImage(bmp, 0, 0)
bmp.Dispose()
End Using
currPage += 1 'Current page is printed, increase index with 1
If currPage < pCount Then 'Are there any further pages in the current image?
e.HasMorePages = True 'yes continue printing
Else 'no
If fileCount = (fileN.Count - 1) Then 'Hase the list anymore files?
e.HasMorePages = False 'No - stop printing all together
Else 'yes
currPage = 0 'Set your index for the current page back to first
fileCount += 1 'Increase the index of the current file
currImage = Image.FromFile(fileN.Item(fileCount)) 'Load the next image (Perhaps if-statements is desired to avoid Null-Reference)
pCount = currImage.GetFrameCount(FrameDimension.Page) 'Load the pagecount of the current image
e.HasMorePages = True 'continue printing
End If
End If
End Sub
I hope this may be of some use to other people.