Problem: In a .NET service I import a number of images, draw on them
with the drawing object, then need to print them, one image per page.
I can get them to print in seperate print jobs -one printdocument per
image - if I print as soon as I'm done with each image, but that's
not really ideal. I'd like to print them all in a batch - print my
print document just once.
The MSDN example, and multiple examples I"ve seen deal with getting a
stream of text, then using ev.hasmorepages true/false to print - but
you can't make a stream from graphics!
Aha! I thought I'll just make an array from my images, then loop
through it in the print event handler - but you can't make that array!
Aha number two - ImageList! But the images don't get put into the
image list correctly!!!!
Summary: How can I get all the images I've created and loop through
them in my print event handler to print all my images, one image per
page.
Code Flow: -THIS IS FOR THE PRINT-NEW-JOB-EVERY-IMAGE method - I've
tried to modify to save all my images in an array of images or
imagelist - no dice.
For each image I import (different every time)
'make bitmap from image
strPath = "path to file"
objBitMap = New Bitmap(strPath)
'lots of drawing using drawing object here
'drawing done
pics = objBitMap
p = New PrintDocument
''call pages sub?
AddHandler p.PrintPage, AddressOf pd_printpage
''name the printing service (que)
p.DocumentName = "GIB Service"
''what to print - class level defined pics
''set orientation
p.DefaultPageSettings.Landscape = True
margins = New Margins(25, 25, 0, 100)
p.DefaultPageSettings.Margins = margins
''which printer
' p.PrinterSettings.PrinterName =
p.PrinterSettings.InstalledPrinters(0)
p.PrinterSettings.PrinterName = "\\faith\pl10"
'MessageBox.Show(p.PrinterSettings.PrinterName)
p.Print()
end sub
NOW COMES THE PRINT EVENT HANDLER: - referred to above.
Private Sub pd_printpage(ByVal sender As Object, ByVal ev As
System.Drawing.Printing.PrintPageEventArgs)
ev.Graphics.DrawImage(pics, New Rectangle(100, 100, pics.Width,
pics.Height), 0, 0, pics.Width, pics.Height, GraphicsUnit.Pixel)
end sub
Help! What I'd like to do in my event handler is this:
For each img in array-o-images OR for each img in
imagelist.images
ev.graphics.drawimage(img)
if this is not the last page then
ev.hasmorepages = true
else
ev.hasmorepages = false
next
But I can't get that to work to save my life!
Hope this helps
James
>.
>
Private Sub pd_printpage(ByVal sender As Object, ByVal ev As
System.Drawing.Printing.PrintPageEventArgs)
Dim z As Integer = 0
ev.Graphics.DrawImage(alImg(z), New Rectangle(10, 10,
alImg(z).Width, alImg(z).Height), 0, 0, alImg(z).Width,
alImg(z).Height, GraphicsUnit.Pixel)
alImg.Remove(alImg(z))
If alImg.Count > 0 Then
ev.HasMorePages = True
Exit Sub
Else
ev.HasMorePages = False
End If
End Sub
"James Westgate" <ja...@nospam.crainiate.com> wrote in message news:<0b0201c34be4$5417abd0$a001...@phx.gbl>...