473,698 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PrintDocument_P rintPage goes into endless loop until e.HasMorePages= False

Whenever I use PrintDocument.P rint() to print a page it goes to
PrintDocument_P rintPage and stays there forever unless I set
e.HasMorePages to False.
When I set it to False it prints the page but is closes the print
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?
Dec 24 '06 #1
6 4603

"moti" <mo****@gmail.c omwrote in message
news:fa******** *************** *********@4ax.c om...
Whenever I use PrintDocument.P rint() to print a page it goes to
PrintDocument_P rintPage and stays there forever unless I set
e.HasMorePages 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.


Dec 25 '06 #2
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.
Dec 25 '06 #3

"moti" <mo****@gmail.c omwrote in message
news:8o******** *************** *********@4ax.c om...
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
Keep in mind that the variables you declare in the icoPrintAll_Cli ck sub
only live in that sub - and those variables cannot be used by the PrintPage
sub - or any other sub. Like I said before - keep in mind that the PrintPage
sub will be called over and over until e.HasMorePages is false, so any
variables you need to keep track of page numbers, line numbers, etc need to
be declared at the top of the module (not the sub) so they won't be
re-initialized on every execution of the PrintPage sub.
here's a tutorial on using the PrintPage eventhandler:
http://www.vbdotnetheaven.com/Upload...1-97cb0652a8c1
Dec 25 '06 #4
Thank you again.
I looked at the link but noticed it had all its logic within
PrintDocument_P rintPage too. Is there any way to get the code out of
it? Otherwise, for each type of list another PrintDocument_P rintPage
sub has to be created (with a dif name) and again all its logic (data
gathering) must be within it or else I have to create an array of
pages (and if the list is 1000 pages?). There has to be another way or
else I must be doing somthing wrong. Could it be that my print is
printing graphic pages? I looked all over and the dif code for
text/image is mostly the same except that text is internally converted
to graphics.
Anyway, thanks for the help and if you can show me any type of VB code
that prints, with its print logic outside of PrintDocument_P rintPage,
it would really be appreciated. As is, I can't even class it because
it still won't get out of PrintDocument_P rintPage without
e.MorePages=Fal se.

On Sun, 24 Dec 2006 22:09:57 -0500, "Hal Rosser"
<hm******@bells outh.netwrote:
>
"moti" <mo****@gmail.c omwrote in message
news:8o******* *************** **********@4ax. com...
>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_ PrintPage, 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_ PrintPage 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. ShowDialog = 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_PrintDocumen t.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

Keep in mind that the variables you declare in the icoPrintAll_Cli ck sub
only live in that sub - and those variables cannot be used by the PrintPage
sub - or any other sub. Like I said before - keep in mind that the PrintPage
sub will be called over and over until e.HasMorePages is false, so any
variables you need to keep track of page numbers, line numbers, etc need to
be declared at the top of the module (not the sub) so they won't be
re-initialized on every execution of the PrintPage sub.
here's a tutorial on using the PrintPage eventhandler:
http://www.vbdotnetheaven.com/Upload...1-97cb0652a8c1
Dec 25 '06 #5

"moti" <mo****@gmail.c omwrote in message
news:nl******** *************** *********@4ax.c om...
Thank you again.
I looked at the link but noticed it had all its logic within
PrintDocument_P rintPage too. Is there any way to get the code out of
it? Otherwise, for each type of list another PrintDocument_P rintPage
sub has to be created (with a dif name) and again all its logic (data
gathering) must be within it or else I have to create an array of
pages (and if the list is 1000 pages?). There has to be another way or
else I must be doing somthing wrong. Could it be that my print is
printing graphic pages? I looked all over and the dif code for
text/image is mostly the same except that text is internally converted
to graphics.
Anyway, thanks for the help and if you can show me any type of VB code
that prints, with its print logic outside of PrintDocument_P rintPage,
it would really be appreciated. As is, I can't even class it because
it still won't get out of PrintDocument_P rintPage without
e.MorePages=Fal se.
You're gonna have a long wait, because until e.HasMorePages = false, the
PrintDocument_P rintPage event will continually continuously over and over
again will repeatedly be called over and over and over.
That is how it works.
Inside the PrintDocument_P rintPage sub, you need to have an if statement
If (everything I want to print has been printed) Then
e.HasMorePages = false
End If

If you don't know how to tell when everything you want to print has been
printed, then maybe Printing isn't the big problem.
Dec 26 '06 #6
Moti,
Whenever I use PrintDocument.P rint() to print a page it goes to
PrintDocument_P rintPage and stays there forever unless I set
e.HasMorePages to False.
Ah! There's the rub!

PrintDocument.P rint is used to print the entire "document", where "document"
is a print job. A "document" (aka print job) contains many pages.

PrintDocument_P rintPage prints one of the possibly many pages that the
document (aka print job) may contain.

As Hal has been trying to state: You need to change your vb code, and
possibly your thinking, such that when you call PrintDocument.P rint you are
prepared for PrintDocument_P rintPage being called multiple times. You should
only need to call PrintDocument.P rint one time for the entire document (aka
print job)!
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.
If you have a 100 page document that you want to print via PrintDocument,
your PrintDocument_P rintPage routine need to be prepared to be called 100
times! When you print this 100 page document; you will call
PrintDocument.P rint once. PrintDocument.P rint will then call
PrintDocument_P rintPage 100 times. On the 100th time you need to set
e.HasMorePages = False.

PrintDocument_P rintPage uses a class/module level field to keep track of
which page its on. Each time it is called it "increments " this class/module
level field to know which page it is printing. The PrintDocument_B eginPrint
event can be used before any pages are printed; for example to set the
class/module level field such that the first page is printed or to allocate
any resources such as pens, brushes, and fonts used during printing. The
PrintDocument.E ndPrint event can be used after all the pages are printed;
for example to release any resources such as pens, brushes, and fonts used
during printing.

--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"moti" <mo****@gmail.c omwrote in message
news:fa******** *************** *********@4ax.c om...
Whenever I use PrintDocument.P rint() to print a page it goes to
PrintDocument_P rintPage and stays there forever unless I set
e.HasMorePages to False.
When I set it to False it prints the page but is closes the print
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?
Dec 26 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4670
by: Knocked Wood | last post by:
Hi, I looked around and can't find anything on this at all and can not get it to work for IE. I'm trying to loop multiple sounds on a game, with three unique variables, when a link is clicked. Something like... <Script Language="JavaScript"> <!-- function playSound(soundName, loops, timeLength){
8
2890
by: Mr. B | last post by:
VB.net (standard) I'm experiencing some difficulties in printing multiple pages using Print Preview. The following is my main parts of my printing subs (excess info deleted for your viewing pleasure). For a single page, the print preview (and an actual print) are OK. Getting the .HasMorePages doesn't seem to be working for me here (unless I'm missing something).
3
8354
by: DGeorge | last post by:
I have a problem where after setting the HasMorePages = True will not print the 2nd Pages. Does anybody have an idea or knows this problem. Thanks for any advice
1
1477
by: Kyle Walz | last post by:
I'm working on an app where each page is a like a form (not Windows form) with a set format. Using MSVB.NET 2003 with 1.1 framework. Here's some code: Private Sub PrintText(ByVal sender As Object, ByVal ev As PrintPageEventArgs) Dim brush As Brush = New SolidBrush(Color.Black) Dim font As Font = New Font("Arial", 10, FontStyle.Regular) ' first page
73
4601
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an endless loop in a line with: if a==b: print 'OK' I mean, it would be of much help to me on my way to understanding Python to know how such prefix code leading to an endless loop can look like and if it is eventually not possible to write such...
2
7901
by: Leo | last post by:
I set HasMorePages to true, but it doesn't let me jump to next page. (Of course, if I remove the HasMorePages = false in my if statement, it will create hundreds of pages). Any suggestion? Thanks in advance. Leo My code to call the print event: .... {
1
11187
by: kig25 | last post by:
Hello, When using the VB.NET PrintDocument class, I seem to be encountering an issue where the sub pd_PrintPage handles PrintDocument.PrintPage (upon continuing if HasMorePages = true) will paint the next page on top of the original page. In a sample data case where the source is long enough to fill three pages, I end up with four calls to pd_PrintPage which render onto two printed sheets. Historical posts in this forum from 2003 and...
0
1564
by: creedence | last post by:
Hello I have a problem with printing data from dataset.I dont know how to make that print is go on to the next page. I know that is something with hasmorepages = true but i dont Know how to use it. Here is my code, so every help is greatful. Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles
2
2929
by: GGSoft | last post by:
Please Can't understand how to use HasMorepages. I spent a lot of time on this task. but I have no result. For examle I want to print every 45 record on each new page. Please Rewrite the following code in correct manner. I dont know where to place HasmorePages=true and HasmorePages=false Private Sub Pr_PrintReg(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pr.PrintPage ...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.