473,856 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with printing unable to advanced to next page

11 New Member
I have asked before and got little responce, So I try and try again.

The code below prints the data in the same place but does not advance the page. I can see the lblnumber change but print in top of the previous one. So my loop is working, I have the hasmorepages= true set right after each cycle till the loop finishes.

Hopefully someone can point out my error.

Thanks David DeWitt

this part calls the printing code
Expand|Select|Wrap|Line Numbers
  1.  Public Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
  3.         Dim Print As New myPrinter
  4.         Call Print.prt()
  6.     End Sub
here is my printing code
Expand|Select|Wrap|Line Numbers
  1. Imports System.Drawing.Printing
  3. Public Class myPrinter
  4.     Public Shared lblnumber As Integer
  5.     Public Shared endlbl As Integer
  6.     Private WithEvents prn As PrintDocument
  8.     Public Sub prt()
  9.         Dim prn As New PrintDocument
  11.         ' Create a PaperSize and specify the custom paper size .
  12.         Dim pkCustomSize1 As New PaperSize("Label Size", 400, 800)
  14.         Using (prn)
  15.             prn.PrinterSettings.PrinterName = My.Settings.Printer
  16.             'to add page size here.   
  17.             prn.DefaultPageSettings.PaperSize = pkCustomSize1
  19.             AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
  20.             prn.Print()
  21.             RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
  22.         End Using
  23.     End Sub
  25.     Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As System.Drawing.Printing.PrintPageEventArgs)
  26.         Dim smFont As New Font("Microsoft San Serif", 10)
  27.         Dim medFont As New Font("Microsoft San Serif", 14)
  28.         Dim lrgFont As New Font("Microsoft San Serif", 18)
  29.         lblnumber = CInt(MainForm.txtStartBoxNUmber.Text)
  30.         endlbl = CInt(MainForm.txtStartBoxNUmber.Text) + CInt(MainForm.txtBoxes.Text)
  32.         Do
  34.             ' return address
  35.             args.Graphics.DrawImage(My.Resources.LOGO_2, 60, 10)
  36.             args.Graphics.DrawString(My.Settings.returnAddress, New Font(smFont, FontStyle.Regular), Brushes.Black, 117, 70)
  37.             args.Graphics.DrawString(My.Settings.returnCity, New Font(smFont, FontStyle.Regular), Brushes.Black, 110, 85)
  38.             ' ship to address
  39.             args.Graphics.DrawString("Ship to:", New Font(medFont, FontStyle.Bold), Brushes.Black, 5, 150)
  40.             args.Graphics.DrawString(MainForm.txtCompanyName.Text, New Font(lrgFont, FontStyle.Bold), Brushes.Black, 30, 175)
  41.             args.Graphics.DrawString(MainForm.txtAttn.Text, New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 210)
  42.             args.Graphics.DrawString(MainForm.txtAddress1.Text, New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 235)
  43.             args.Graphics.DrawString(MainForm.txtAddress2.Text, New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 260)
  44.             args.Graphics.DrawString(MainForm.txtCity.Text & ",  " & MainForm.txtState.Text & "  " & MainForm.txtZip.Text, New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 285)
  45.             ' Package & Order information
  46.             args.Graphics.DrawString("P.O. #" & MainForm.txtPO.Text, New Font(smFont, FontStyle.Bold), Brushes.Black, 30, 370)
  47.             args.Graphics.DrawString("Order #" & MainForm.txtOrderNumber.Text, New Font(smFont, FontStyle.Bold), Brushes.Black, 30, 390)
  48.             args.Graphics.DrawString("Box #" & lblnumber, New Font(smFont, FontStyle.Bold), Brushes.Black, 30, 410)
  50.             lblnumber = lblnumber + 1
  51.             args.HasMorePages = True
  52.         Loop Until lblnumber = endlbl
  55.         args.HasMorePages = False
  57.     End Sub
  58. End Class
Jan 8 '07 #1
4 2493
4,871 Recognized Expert Specialist
I believe that the loop is the problem:
Expand|Select|Wrap|Line Numbers
  1. Do Until lblnumber = endlbl
  2. {rest of code}
  3. Loop
Jan 8 '07 #2
11 New Member
Try changing the do-loop as suggested. Still works the same. The only item that should change on each page is the lblnumber. It does changes but the page does not advance, so the information is printed on top of itself.
In the days of quick basic I could send a form feed.

Hope someone can figure out my error,
David DeWitt
Jan 8 '07 #3
4,871 Recognized Expert Specialist
Have you tried to comment out the line:
Expand|Select|Wrap|Line Numbers
  1. args.HasMorePages = False
My suggestion is to comment out lines until it stops working and then progress forward again. Sometimes it a case of one step backward and two forward. It must be frustrating to be so close :(.
Jan 8 '07 #4
LX Apostal
1 New Member
This reply may be too late to help David DeWitt, but here is an answer that may help the next person...

Help with printing unable to advanced to next page - using PrintDocument--------------------------------------------------------------------------------

1) In David's code he has 1/2 the answer that everyone has been looking for. He calls RemoveHandler() to remove the handler when he was done drawing.
AddHandler prn.PrintPage, AddressOf Me.PrintPageHan dler
RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHan dler
In the code I wrote that wasn't working. I was calling AddHandler more than once, which caused my code to draw more than one page on one sheet of paper.
For example:
Say I add 3 handlers, H1, H2, and H3.
When I ask to PrintDocument1. Print(); the system calls H1 to handle a page, but the send to printer occurred when it calls H1 for the next page. My code sets the more pages flag "args.HasMorePa ges = True". But the system call H2 (not H1 again) which caused my code to move to drawing page two (2). My code sets the more pages flag "args.HasMorePa ges = True". Then the system call H3 (not H1 nor H2 again) which caused my code to move to drawing page three (3). Then my code says there are no more pages "args.HasMorePa ges = False". Then the system would call H1 again which causes the page to print, but now we are done, remember "args.HasMorePa ges = False"; so no more calls to Handlers, otherwise I would have seen a page ejection for each Handler.
2) In David's code, the other half of the answer is you shouldn't set the "args.HasMorePa ges = True" flag in a loop that you are not exiting. David's code must exit the sub procedure PrintPageHandle r() after drawing the first (1) page. The system will call PrintPageHandle r() back again, and at that time he should draw page two (2). This means he has to save off the starting (or ending) record he has processed and start the second page on the record he left off on.

For example:
Private m_nLeftOffAt As Integer = 0
Private m_bStartingOver As Boolean = True

Private Sub PrintPageHandle r( ... )
Dim nItemsOnThisPag e As Integer
Dim nItemsWantedPer Page As Integer

' ... ' remove for readability

lblnumber = CInt(MainForm.t xtStartBoxNUmbe r.Text)
endlbl = CInt(MainForm.t xtStartBoxNUmbe r.Text) + CInt(MainForm.t xtBoxes.Text)

If Not m_bStartingOver Then
lblnumber = nLeftOffAt
End If

nItemsOnThisPag e = 0
nItemsWantedPer Page = 60
nItemsOnThisPag e = nItemsOnThisPag e + 1

' return address
args.Graphics.D rawImage(My.Res ources.LOGO_2, 60, 10)
' ... ' remove for readability
args.Graphics.D rawString("Box #" & lblnumber, New Font(smFont, FontStyle.Bold) , Brushes.Black, 30, 410)

lblnumber = lblnumber + 1

Loop Until (lblnumber = endlbl) Or (nItemsOnThisPa ge > nItemsWantedPer Page)

If lblnumber >= endlbl Then
args.HasMorePag es = False
m_bStartingOver = True
nLeftOffAt = lblnumber
args.HasMorePag es = True
End If
End Sub

Hope this helps someone.
Alex Apostal
Apr 13 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: abcd | last post by:
kutthaense Secretary Djetvedehald H. Rumsfeld legai predicted eventual vicmadhlary in Iraq mariyu Afghmadhlaistmadhla, kaani jetvedehly after "a ljetvedehg, hard slog," mariyu vede legai pressed Pentagjetvedeh karuvificials madhla reachathe strategy in karkun campaign deshatinst terrorism. "mudivae maretu winning or losing karkun global varti jetvedeh terror?" Mr. Rumsfeld adugued in a recent memormariyuum. vede velli jetvedeh madhla...
by: Darcy Kahle | last post by:
I am trying to do some advanced printing in python using the win32ui module, and have run into an issue. I need to print a page landscape. As I could not determine how to specify the orientation of the printing, I arranged the graphic elements on the page the way it should be. When I got to printing text, it went across the page, not down as I need it to go. I tried to use the hDC.SetWorldTransform(0, -1, 1, 0, 0, 0) command to rotate...
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been selected. For example, if I were to have 5 pages with every second page printing, I would get the following results: Page 1 = Print OK Page 2 = Blank Page 3 = Print OK Page 4 = Blank
by: steven | last post by:
I am creating some financial reports in Access 2000, and I am having problem that I can't resolve. The report sorts information first by vendor, then by budget line number. It generates the information I need accurately, but I am having problems with the layout. -The budget line header contains information about the vendor--it looks great. -The budget line footer contains the sum, and I am not having any problems there.
by: Suzanka | last post by:
Hello, I have an application written in C# on visual studio .NET. It is a web aplication. The application consists of many different forms, that users occassionaly want to print out for filing. When they log to application (through web browser) and choose the print option, on the right margin few cm get cut off (so some fields do not print out). Is there any function that ensure that when user pritns he gets the
by: Amirallia | last post by:
Hello! I have a wecontrol table in a page, this table has a number of variable rows depending of the choice of the user. But when the table has a large number of rows, the printing of the page requires 2 pages . The first page is ok, but in the second page of the printing I have no ligne of the row and no ligne of the column printing on the page!
by: Dreamtime | last post by:
Hi I am using Visual Studio 2005 and the bundled Crystal Reports (previously I used .net 2003 and bundled Crystal Reports for 2 years - same issues!) I have a report which is displayed in the crystal reports viewer. This report needs to be printed. Its that simple! I would like to use the report.printtoprinter method as this is direct
by: Webstorm | last post by:
Hi, I hope someone can help me sort this out a bit, Im completely lost. Here is the page I am working on: http://www.knzbusinessbrokers.com/default.asp I have 3 search critera that I need to use when querying the database. Right now it is only looking for a match on one of those dropdowns and not all 3. can anyone help? Here is the code: <form BOTID="0" METHOD="POST" action="businessforsale_interface/Results/test3.asp">
by: Bigalan | last post by:
Hello, i am relatively new to PHP and i am struggling with printing multiple search results on to different pages. The code below works ok but when you click on next page button, it brings up a blank screen. I think it might have something to do with resetting the $found variable. Can you have a quick look? any suggestions would be greatly appreciated. <? if ($_GET) $vars=$_GET; else $vars=$_POST; $found = $vars;
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,...
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...
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...
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,...
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...
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...
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...
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();...
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

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.