hi all i am trying to print and have setup a print priview i would like to set paper size and make it so when it goes to a certain amount it prints on next but when i try this page count just keeps going up i have tried a few things with no luck is there a guide or does anybody know what i am doing wrong ?
VB.NET:
Private Sub PrintDocument2_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage
Dim txt As String = ""
Dim txt2 As String = ""
Dim txt3 As String = ""
'################################
Dim myFont As New Font("Times New Roman", 30, FontStyle.Bold, GraphicsUnit.Pixel)
Dim value As String = ""
'value = "This is a test" & Space(25) & "And scores"
value = My.Settings.CompanyName
Using sf As New StringFormat()
Dim rect As New Rectangle(3 * 15, 20, 700, 40)
sf.Alignment = StringAlignment.Center
'e.Graphics.DrawRectangle(Pens.Green, rect)
e.Graphics.DrawString(value, myFont, Brushes.Black, rect, sf)
'e.Graphics.DrawString(value, myFont, Brushes.Green)
End Using
For Each item As String In ListBox1.Items
txt &= vbCrLf & item
Next item
For Each item2 As String In ListBox2.Items
txt2 &= vbCrLf & FormatCurrency(item2)
Next item2
txt3 = txt2.Substring(vbCrLf.Length)
txt = txt.Substring(vbCrLf.Length)
Dim jpk
jpk = ListBox2.Items.Count * 32
Dim itemcounter As Integer = 0
'###########################drawing starts here#########################3
'#############drawing line################
Dim blackPen As New Pen(Color.Black, 1)
' Create points that define line.
Dim point1 As New Point(10, 60)
Dim point2 As New Point(815, 60)
' Draw line to screen.
e.Graphics.DrawLine(blackPen, point1, point2)
'#############drawing line################
Using the_font As New Font("Times New Roman", 20, FontStyle.Regular, GraphicsUnit.Point)
' Left aligned.
Using sf As New StringFormat()
Dim rect As New Rectangle(1 * 100, 100, 400, jpk)
sf.Alignment = StringAlignment.Near
'e.Graphics.DrawRectangle(Pens.Red, rect)
e.Graphics.DrawString(txt, the_font, Brushes.Black, rect, sf)
End Using
' Centered.
'Using sf As New StringFormat()
'Dim rect As New Rectangle(3 * 100, 100, 150, 250)
'sf.Alignment = StringAlignment.Center
'e.Graphics.DrawRectangle(Pens.Green, rect)
'e.Graphics.DrawString(txt, the_font, Brushes.Green, _
' rect, sf)
'End Using
' Right aligned.
Using sf As New StringFormat()
Dim rect As New Rectangle(5 * 100, 100, 100, jpk)
sf.Alignment = StringAlignment.Far
'e.Graphics.DrawRectangle(Pens.Blue, rect)
e.Graphics.DrawString(txt3, the_font, Brushes.Black, _
rect, sf)
' itemcounter += 1
'If itemcounter = 4 Then
'itemcounter = 0
' End If
End Using
End Using
'If (3 > itemcounter) Then
'e.HasMorePages = True
'Else
'e.HasMorePages = False
'End If
'#############drawing line################
Dim jpk2 As Integer
jpk2 = jpk + 100
Dim blackPen2 As New Pen(Color.Black, 1)
' Create points that define line.
Dim point3 As New Point(10, jpk2)
Dim point4 As New Point(815, jpk2)
' Draw line to screen.
e.Graphics.DrawLine(blackPen2, point3, point4)
'#############drawing line################
'###Displays total in lable1#####
Dim decTotalCost As Decimal
Dim X As Integer = 1
' Add items from list for display
Dim tempstring As String
For X = 0 To (ListBox2.Items.Count - 1)
If Not ListBox2.Items.Item(X) = "0" Then
tempstring = CStr(ListBox2.Items.Item(X))
decTotalCost = decTotalCost + CDec(tempstring)
End If
Next
Dim jpk3 As Integer
jpk3 = jpk + 110
value = "Total " & FormatCurrency(decTotalCost)
e.Graphics.DrawString(value, myFont, Brushes.Black, 410, jpk3)
'#################################################
If ListBox2.Items.Count = 5 Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub