473,732 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing more than one page in VB.Net using PrintDocument object

Hello,

I'm trying to print more than one page using the PrintDocument object.
I set "e.HasMoreP ages = True" after completeing the first page in the
"PrintDocument1 _PrintPage" subroutine, and then "exit sub". When
"PrintDocument1 _PrintPage" is called for the second page, it skips to the
code to print the second page and then returns, setting "e.HasMoreP ages =
False".

Everything seems to work however, when I look at my printout the second page
overwrites the first page. How do I keep the second page from overwriting
the first page?

--
Islay
Feb 8 '06 #1
3 10590
> I'm trying to print more than one page using the PrintDocument object.
I set "e.HasMoreP ages = True" after completeing the first page in the
"PrintDocument1 _PrintPage" subroutine, and then "exit sub". When
"PrintDocument1 _PrintPage" is called for the second page, it skips to the
code to print the second page and then returns, setting "e.HasMoreP ages =
False".

Everything seems to work however, when I look at my printout the second page
overwrites the first page. How do I keep the second page from overwriting
the first page?


I don't know why you are having a problem, but I do know that I ran into
something fishy regarding e.HasMorePages. The documentation claims that it
is an ordinary boolean property, but I had problems when I accessed it more
than once during a PrintPage event. So, I now compute a local boolean
HasMorePages for my own purposes, and I guarantee one and only one execution
per event of
e.HasMorePages = HasMorePages
and no other accesses to e.HasMorePages. If you use e.HasMorePages more
widely than this, you may have the same kind of problem I did. FYI FW 1.1,
Windows XP, all SPs current.

Feb 8 '06 #2
Thanks for responding so quickly. I tried your suggestion but it didn't help.
I also noticed something else strange. My print routine is called more than
once even if I set "e.HasMoreP ages = false" before I exit after creating the
first page. I only access e.HasMorePages once in the routine. The second
page is still overwriting the first page.
--
Islay
"AMercer" wrote:
I'm trying to print more than one page using the PrintDocument object.
I set "e.HasMoreP ages = True" after completeing the first page in the
"PrintDocument1 _PrintPage" subroutine, and then "exit sub". When
"PrintDocument1 _PrintPage" is called for the second page, it skips to the
code to print the second page and then returns, setting "e.HasMoreP ages =
False".

Everything seems to work however, when I look at my printout the second page
overwrites the first page. How do I keep the second page from overwriting
the first page?


I don't know why you are having a problem, but I do know that I ran into
something fishy regarding e.HasMorePages. The documentation claims that it
is an ordinary boolean property, but I had problems when I accessed it more
than once during a PrintPage event. So, I now compute a local boolean
HasMorePages for my own purposes, and I guarantee one and only one execution
per event of
e.HasMorePages = HasMorePages
and no other accesses to e.HasMorePages. If you use e.HasMorePages more
widely than this, you may have the same kind of problem I did. FYI FW 1.1,
Windows XP, all SPs current.

Feb 8 '06 #3
I also found that VB.Net (VS.Net 2003, .Net Framework 1.1) HasMorePages is
not functioning as designed (or as documented). It appears that the
PrintPage event will cycle twice whether HasMorePages is set to "True" or
"False". In my case, when I had additional pages of information to print,
the page eject was not being sent to the printer until the second cycle.
This resulted in one page printing on-top of another page. After much hair
pulling, I determined that it was a bug and wrote code to work around this
bug.

Example:
' Dim a Class Variable such as:
Dim pageCycle as boolean = False

'in the PrintPage handler, include the following:
'************** *************** **********
'This code is here to handle a bug in the PrintPage event that will
not
'eject a page until the event cycles through two event cycles when the
'System.Drawing .Printing.Print PageEventArgs.H asMorePages property has
'been set to true.
If printcycle = True Then
printcycle = False
Exit Sub
End If
printcycle = True
'************** *************** **********

To work around the "two Cycle" PrintPage event when HasMorePages is "False",
include code in your loop to exit the loop if the string buffer is nothing.

Example:
Dim line As String = Nothing

' Calculate the number of lines per page.
linesPerPage = ev.MarginBounds .Height /
printFont.GetHe ight(ev.Graphic s)

'Now iterate over the stream and printing out each line

While count < linesPerPage
line = stringToPrint.R eadLine()
If line Is Nothing Then
Exit While
End If
yPos = topMargin + count * printFont.GetHe ight(ev.Graphic s)
ev.Graphics.Dra wString(line, printFont, Brushes.Black,
leftMargin, _
yPos, New StringFormat)
count += 1
End While

I hope Microsoft reads this disscussion forum because I do not know how to
report bug.

Hope this helps

Mar 2 '06 #4

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

Similar topics

3
12375
by: Randy | last post by:
Hello, I'm trying to print a dataGrid using PrintDocument control. My datagrid has about 23 columns so it is fairly wide. When I use the PrintControl, it prints only the part of the dataGrid that is visible on screen. I tried using PrintPreviewDialog too but it still only shows just what is visible in the dialog that houses the dataGrid. I want to get all the datagrid printed. Maybe wrapping it would be the only way to print all of...
0
1185
by: Neil Kimber | last post by:
Hi, I'm using the Cache object to persist some values between pages. I'm setting the expiration for 2 minutes. I'm actually storing Bitmap streams in the cache. In this way, one page can draw an image and store it and another page can be responsible for streaming it to the browser. This approach works well in that the Bitmap is correctly stored, the other page can read the data and stream it correctly. Once streamed I do not want to...
1
6274
by: Krich | last post by:
I am still new on printdocument object. I have a problem try to print graphic object. I have one graphics object. How to print it? I try to print it in PrintPage event using this syntax e.Graphics = grhObj by grhObj is graphics object that already has string, line or other image in it. It is very difficult to recreate this object in PrintPage event.
3
6319
by: Mika M | last post by:
Hi all! I have made an application for printing simple barcode labels using PrintDocument object, and it's working fine. Barcode printer that I use is attached to the computer, and this computer has drivers installed for this printer, and this printer is shared for the network. Question 1:
0
1765
by: Dominator.Legend | last post by:
Hallow every one, i have a problem using .net user control with the <OBJECT> tag, I made a normal user control in C#, then i use the regasm to register it, also i use the option regfile to generate the *.reg file and then merge it, After merging it i open the reg file, which was as follow. REGEDIT4
5
5206
by: girishmat | last post by:
how to embed or open microsoft word file in a page using php script
7
11404
by: pamela fluente | last post by:
hi, What is the cleanest and effective way to use the PrintDocument object to print directly to a pdf file "myfile.pdf" (with no prompt to the user: just print to file and make pdf) ? Does anyone have a simple code snippet? Either VB or C# will be perfect.
0
2372
by: thirunavukarasukm | last post by:
Hai.... To print Html page using PrintDialog and Print Document i am created one windows appication.. the windows application have many pages in my booking page i have two buttons one btnprint,btnclose
1
4131
by: fastvarun | last post by:
Can anybody help me how to remove url while print out of a page using javascript window.print() plz help me...........................
0
8774
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
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
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
8186
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
6735
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
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.