Thank you for replying.
Originally I had all my code outside PrintPage. I had a module
variable called MorePages and did a PrintDocument.P rint() to print the
page when it was full. What it does is go to the
PrintDocument_P rintPage, where I set e.HasMorePages to MorePages. But
it never gets out of PrintDocument_P rintPage until
e.HasMorePages= False. If I set it to False then it does get out of
PrintDocument_P rintPage and closes the print file, which creates every
page as a separate file. The only way around this was to put all my
print logic in PrintDocument_P rintPage.
The following code was my original code that did not work:
Private Sub icoPrintAll_Cli ck(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles icoPrintAll.Cli ck
'Dim FirstPage As Boolean = True
'MorePages = True
'For I = 0 To DetRowCount - 1
' s = dedv.Table.Rows .Item(I).Item(1 5).ToString
' If File.Exists(tbD ocPath.Text + "\" + s) And InStrRev(s,
".") = 0 Then
' PictureDet.Imag e = Image.FromFile( tbDocPath.Text +
"\" + s)
' m_PrintBitmap = CType(PictureDe t.Image, Bitmap)
' m_PrintDocument = New PrintDocument
' m_PrintBitmap.S etResolution(20 0, 200)
' If I = DetRowCount - 1 Then MorePages = False
' PrintDialog1.Do cument = m_PrintDocument
' If FirstPage Then FirstPage = False : If Not
(PrintDialog1.S howDialog = System.Windows. Forms.DialogRes ult.OK) Then
Exit Sub
' m_PrintDocument .Print()
' End If
'Next
'MorePages = False
'm_PrintDocumen t.Print()
End Sub
' Print the form image.
Private Sub m_PrintDocument _PrintPage(ByVa l sender As Object,
ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles
m_PrintDocument .PrintPage
e.Graphics.Draw Image(m_PrintBi tmap, 0, 0)
If MorePages = False Then
e.HasMorePages = False
Else
e.HasMorePages = True
End If
End Sub
On Sun, 24 Dec 2006 19:38:57 -0500, "Hal Rosser"
<hm******@bells outh.netwrote:
>
"moti" <mo****@gmail.c omwrote in message
news:fa******* *************** **********@4ax. com...
>Whenever I use PrintDocument.P rint() to print a page it goes to
PrintDocument_ PrintPage and stays there forever unless I set
e.HasMorePag es to False.
Normal
>When I set it to False it prints the page but is closes the print
file.
Don't open the file in the PrintPage event - open it in a different
sub then let the PrintPage sub get called from there.
then it won't close the file.
>>The effect is that it prints all my pages but creates a print
job for each page. So if I print 100 pages I get 100 print jobs.
The only way I went around this was to put all my page-filling code
within PrintDocument_P rintPage.
Is there a way around this?
Since the PrintPage event get called over and over until HasMorePages is
false, you may want to use module-level variables to keep track of which
page you're on and which line you're on.