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

Home Posts Topics Members FAQ

printing multiple pages

I can't seem to get the logic for printing multiple pages. I know I have to
do a comparison between the bottom margin and the position of the next line
to be printed and initiate a has more pages condition when they are equal. I
have included my code for the printpage handler below. When I run it for an
array that takes up less than a page its OK. When I run it on a larger array
it goes into an infinite loop creating identical pages of the first set of
lines?

Set me straight. (most of this code is setup go to label 1600 for the crux)

Private Sub PrintDocument2_ PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles _
PrintDocument2. PrintPage
Try
PrintDocument2. DefaultPageSett ings.Landscape = True
PrintDialog2.Al lowSomePages = True

Dim x As Single = e.MarginBounds. Left
Dim y As Single = e.MarginBounds. Top
Dim lineheight As Single = FontDialog1.Fon t.GetHeight(e.G raphics)
Dim XIncrement As Single
Dim i, j As Integer

Dim max As Single = 0
Dim temp(Grid.rows + 1, Grid.cols + 1) As Double
Array.Copy(Grid .array, temp, temp.Length)
For i = 1 To Grid.rows
For j = 1 To Grid.cols
If CStr(temp(i, j)).Length > max Then max = CStr(temp(i,
j)).Length
Next
Next
Dim solidBrush As New solidBrush(Font Dialog1.Color)

For i = 1 To Grid.rows
1600: If y + lineheight < e.MarginBounds. Bottom Then
For j = 1 To Grid.cols
e.Graphics.Draw String(CStr(tem p(i, j)),
FontDialog1.Fon t, solidBrush, x + XIncrement, y)
XIncrement += (max * FontDialog1.Fon t.SizeInPoints)
+ 10
Next
Else
e.HasMorePages = True
y = 0
GoTo 1600
End If
y += lineheight
Next

Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
end sub
--
mark
Nov 21 '05 #1
1 4889
Never mind I have it now:

Try
PrintDocument2. DefaultPageSett ings.Landscape = True
PrintDialog2.Al lowSomePages = True

Dim pagenumber As Integer = 0
Dim x As Single = e.MarginBounds. Left
Dim y As Single = e.MarginBounds. Top
Dim lineheight As Single = FontDialog1.Fon t.GetHeight(e.G raphics)
Dim XIncrement As Single
Dim i, j, k, p As Integer

Dim max As Single = 0
Dim temp(Grid.rows + 1, Grid.cols + 1) As Double
Array.Copy(Grid .array, temp, temp.Length)
For i = 1 To Grid.rows
For j = 1 To Grid.cols
If CStr(temp(i, j)).Length > max Then max = CStr(temp(i,
j)).Length
Next
Next
Dim solidBrush As New solidBrush(Font Dialog1.Color)
'Do
For i = offset To Grid.rows
XIncrement = 0
For j = 1 To Grid.cols
e.Graphics.Draw String(CStr(tem p(i, j)),
FontDialog1.Fon t, solidBrush, x + XIncrement, y)
XIncrement += (max * FontDialog1.Fon t.SizeInPoints) + 10
Next
offset += 1
If y + lineheight > e.MarginBounds. Bottom Or offset >
Grid.rows Then Exit For
y += lineheight
Next

If offset < Grid.rows Then
e.HasMorePages = True
Else
offset = 1
End If

"mark" wrote:
I can't seem to get the logic for printing multiple pages. I know I have to
do a comparison between the bottom margin and the position of the next line
to be printed and initiate a has more pages condition when they are equal. I
have included my code for the printpage handler below. When I run it for an
array that takes up less than a page its OK. When I run it on a larger array
it goes into an infinite loop creating identical pages of the first set of
lines?

Set me straight. (most of this code is setup go to label 1600 for the crux)

Private Sub PrintDocument2_ PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles _
PrintDocument2. PrintPage
Try
PrintDocument2. DefaultPageSett ings.Landscape = True
PrintDialog2.Al lowSomePages = True

Dim x As Single = e.MarginBounds. Left
Dim y As Single = e.MarginBounds. Top
Dim lineheight As Single = FontDialog1.Fon t.GetHeight(e.G raphics)
Dim XIncrement As Single
Dim i, j As Integer

Dim max As Single = 0
Dim temp(Grid.rows + 1, Grid.cols + 1) As Double
Array.Copy(Grid .array, temp, temp.Length)
For i = 1 To Grid.rows
For j = 1 To Grid.cols
If CStr(temp(i, j)).Length > max Then max = CStr(temp(i,
j)).Length
Next
Next
Dim solidBrush As New solidBrush(Font Dialog1.Color)

For i = 1 To Grid.rows
1600: If y + lineheight < e.MarginBounds. Bottom Then
For j = 1 To Grid.cols
e.Graphics.Draw String(CStr(tem p(i, j)),
FontDialog1.Fon t, solidBrush, x + XIncrement, y)
XIncrement += (max * FontDialog1.Fon t.SizeInPoints)
+ 10
Next
Else
e.HasMorePages = True
y = 0
GoTo 1600
End If
y += lineheight
Next

Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
end sub
--
mark

Nov 21 '05 #2

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

Similar topics

3
7192
by: John Sutor | last post by:
Does anyone know how to print multiple page documents? I can print from a test box or a one page document, but not one with multiple pages.
10
23335
by: Jeff B. | last post by:
Has anyone come across a decent algorithm for implementing word wrap features in .net printing? I have a small component that uses basic printing techniques (i.e. e.Graphics.DrawString in a PrintPage event of a PrintDocument object) to send some formatted text to the printer. However, if the lines are too long they run off the page rather than wrapping around. I'm sure I can spend the time and come up with a word wrapping algorithm but...
4
3735
by: Jay | last post by:
Still can't seem to find a solution to printing a lengthy datagrid on multiple pages including datagrid headeron each page. I am not using Crystal Reports or Reporting Services or VStudio. Any idea how this can be done? Any links, examples Thanks a lot.
2
8204
by: ray well | last post by:
hi, i need to print multiple pages on a printer. this is what i'm using now Sub Print() Dim PrintDoc As New PrintDocument AddHandler PrintDoc.PrintPage, AddressOf Me.PrintText Do While bPrintingNotDone PrintDoc.Print()
6
482
by: Bill | last post by:
Hi I am trying to get my listbox items to print if they stream past the one page mark. my code is working for one page of information (if the e.hasmorepages) is not there. But I am having trouble getting it to print on multiple pages. The second page will not print at all. Thanks in advance
6
4096
by: Siv | last post by:
Hi, I am getting into printing with VB.NET 2005 and want to implement the usual capability that a user can select a selection of pages. I have a report that is generated by my application that if the user wants all pages will produce 3 pages. I want to offer the user the ability to select via the print dialog that only pages 1 and 2 of it are printed or possibly pages 1 and 3 but not 2. At the moment I can produce all three pages...
0
1347
by: ben.agnoli | last post by:
I have written the below class for printing out large jpg files (1 page wide, multiple pages high) over multiple pages. The class will get instantiated multiple times at once by a windows service. For each page that the class prints, it gets visibly slower, when the third document, third page and onwards starts to print, it takes over 20 seconds a page, am I doing something wrong, or is this the wrong way to go about the task (could be...
18
11329
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing classes, for each of the checked rows in the GridView. This works fine in the Visual Studio 2005 development environment on localhost. But, when I move the page to the web server, I get the error "Settings to access printer...
0
2857
it0ny
by: it0ny | last post by:
Hi guys, thanks I am fairly new to this forum so I hope I chose the right place to post this question. I try to make my program printout a deposit's report. I created a class to store the printing printing data and the actual database data in a recordset. the class looks like this: Public Class BRPDD 'Balance Report PrintingDocument Data Public totalReceiptsNum As Integer Public totalLicFee As Double
1
2904
by: charitha0 | last post by:
Hi, Can any one help in printing a html table content (dynamically generated which spreads accorss multiple pages ) in landscape by default. The following code does not work when we have a table with lot of rows which spans accross multiple pages. Nothing shows up in print preview <html> <head> <object id="factory" viewastext style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
0
9916
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
9762
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
11057
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...
1
10782
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
7094
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
5958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4575
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
2
4174
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3201
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.