473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.PrintPageEventArgs) Handles _
PrintDocument2.PrintPage
Try
PrintDocument2.DefaultPageSettings.Landscape = True
PrintDialog2.AllowSomePages = True

Dim x As Single = e.MarginBounds.Left
Dim y As Single = e.MarginBounds.Top
Dim lineheight As Single = FontDialog1.Font.GetHeight(e.Graphics)
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(FontDialog1.Color)

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

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

Try
PrintDocument2.DefaultPageSettings.Landscape = True
PrintDialog2.AllowSomePages = 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.Font.GetHeight(e.Graphics)
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(FontDialog1.Color)
'Do
For i = offset To Grid.rows
XIncrement = 0
For j = 1 To Grid.cols
e.Graphics.DrawString(CStr(temp(i, j)),
FontDialog1.Font, solidBrush, x + XIncrement, y)
XIncrement += (max * FontDialog1.Font.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.PrintPageEventArgs) Handles _
PrintDocument2.PrintPage
Try
PrintDocument2.DefaultPageSettings.Landscape = True
PrintDialog2.AllowSomePages = True

Dim x As Single = e.MarginBounds.Left
Dim y As Single = e.MarginBounds.Top
Dim lineheight As Single = FontDialog1.Font.GetHeight(e.Graphics)
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(FontDialog1.Color)

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

Catch ex As Exception
MsgBox(ex.Message)
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
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
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...
4
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...
2
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...
6
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...
6
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...
0
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....
18
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...
0
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.