Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need to Print Multiple Images I've Generated - how to reference multiple images in print handler

29 views
Skip to first unread message

mykidisgollum

unread,
Jul 16, 2003, 4:37:13 PM7/16/03
to
Greetings All!

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!

James Westgate

unread,
Jul 16, 2003, 5:50:53 PM7/16/03
to
1. Create an arraylist object and use the add method to
add each picture (or an instance if a strucutre or class
that contains your picture and additional information)
2. Add your pictures to the array list
3. in your print handler declare a static variable (Static
intCount as integer). Set the static variable = the index
of the array list your last printed, add one each time in
the print handler, if you have reached to end of the array
list, set hasmorepages = false

Hope this helps
James

>.
>

mykidisgollum

unread,
Jul 17, 2003, 12:18:46 PM7/17/03
to
Bingo!!! Works like a charm - new print handler as follows:
-note how I'm removing my arraylist item each time - to simulate a
stream - most folks printing text - do some kind of a for loop here
until there stream reaches a max number of lines - but in my case each
image represents the max stream value - then must exit sub and return
with havemorepages set to true.

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>...

0 new messages