C
Caroline
the code line e.has more pages true is hit, but it does not create a 2nd
page, instead, I get one page with the items from the 2nd page printed on top
of the 1st page.
Here is my code. Thank you in advance for any help.
Best regards, Caroline
********************************************************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrintFarmPlacards.Click
Try
If lvActiveFlocks.SelectedItems.Count = 0 Then
MsgBox("Please select at least 1 farm to print a barcode.",
MsgBoxStyle.OkOnly, "Error. No farm selected.")
Exit Sub
End If
Dim frmPrinter As New frmPrinterDialog(PrinterToUse)
frmPrinter.ShowDialog(Me)
If frmPrinter.cboPrinter.Text <> "" Then
PrinterToUse = frmPrinter.cboPrinter.Text
If PrinterToUse <> "" Then 'else it will use the default
printer
prndoc.PrinterSettings.PrinterName = PrinterToUse
End If
prndoc.DocumentName = "Farm Placard Barcodes"
AddHandler prndoc.PrintPage, New
System.Drawing.Printing.PrintPageEventHandler(AddressOf
PrintFarmDocumentOnPrintPage)
prndoc.Print()
MsgBox("Farm Placard Barcodes Sent to Printer.")
Barcode2.RefreshImage()
End If
Catch
MsgBox("An error occurred while trying to print; Check to make
sure the print driver is installed and working properly.", , "ERROR:")
End Try
End Sub
Private Sub PrintFarmDocumentOnPrintPage(ByVal sender As Object, ByVal
ppea As PrintPageEventArgs)
Dim index As Integer = 0
Dim grfx As System.Drawing.Graphics = ppea.Graphics
Dim CurrentY As Integer = 125
Dim CurrentX As Integer = 0
Dim intCount As Integer = 0
Dim intLabelCount As Integer = 0
Dim intTotalLabels As Integer = 0
Dim strFarmNo() As String
Dim strFarmName() As String
Dim ItemsPerPage As Single = 0
Dim strFlockNo() As String
intCount = lvActiveFlocks.SelectedItems.Count
For index = lvActiveFlocks.SelectedItems.Count - 1 To 0 Step -1
Do Until ItemsPerPage > 11
If intCount > 0 Then
ReDim strFarmNo(0 To index)
ReDim strFarmName(0 To index)
ReDim strFlockNo(0 To index)
If lvActiveFlocks.SelectedItems.Count > 0 Then
strFarmName(index) =
(lvActiveFlocks.SelectedItems.Item(index).Text)
strFarmNo(index) =
(lvActiveFlocks.SelectedItems.Item(index).SubItems(1).Text)
strFlockNo(index) =
(lvActiveFlocks.SelectedItems.Item(index).SubItems(2).Text)
End If
Barcode2.DataToEncode = strFarmNo(index) &
strFlockNo(index)
Barcode2.ShowText = True
Barcode2.CaptionAbove = strFarmName(index)
Barcode2.BarHeightCM = 1.5
grfx.PageUnit = GraphicsUnit.Millimeter
grfx.PageScale = 1.0F
grfx.DrawString(Me.Text, Me.Font, Brushes.Black, 0, 0)
Barcode2.PaintOnGraphics(grfx, CurrentX, CurrentY)
ItemsPerPage = ItemsPerPage + 1
intCount = intCount - 1
intLabelCount = intLabelCount + 1
If intLabelCount < 3 Then
CurrentX = CurrentX + 1800
Else
CurrentY = CurrentY + 1400
CurrentX = 0
intLabelCount = 0
End If
Else
ItemsPerPage = 12
End If
Loop
If intCount > 0 Then
ppea.HasMorePages = True
ItemsPerPage = 1
CurrentX = 125
CurrentY = 0
Else
ppea.HasMorePages = False
Exit Sub
End If
Next
End Sub
****************************************************
page, instead, I get one page with the items from the 2nd page printed on top
of the 1st page.
Here is my code. Thank you in advance for any help.
Best regards, Caroline
********************************************************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrintFarmPlacards.Click
Try
If lvActiveFlocks.SelectedItems.Count = 0 Then
MsgBox("Please select at least 1 farm to print a barcode.",
MsgBoxStyle.OkOnly, "Error. No farm selected.")
Exit Sub
End If
Dim frmPrinter As New frmPrinterDialog(PrinterToUse)
frmPrinter.ShowDialog(Me)
If frmPrinter.cboPrinter.Text <> "" Then
PrinterToUse = frmPrinter.cboPrinter.Text
If PrinterToUse <> "" Then 'else it will use the default
printer
prndoc.PrinterSettings.PrinterName = PrinterToUse
End If
prndoc.DocumentName = "Farm Placard Barcodes"
AddHandler prndoc.PrintPage, New
System.Drawing.Printing.PrintPageEventHandler(AddressOf
PrintFarmDocumentOnPrintPage)
prndoc.Print()
MsgBox("Farm Placard Barcodes Sent to Printer.")
Barcode2.RefreshImage()
End If
Catch
MsgBox("An error occurred while trying to print; Check to make
sure the print driver is installed and working properly.", , "ERROR:")
End Try
End Sub
Private Sub PrintFarmDocumentOnPrintPage(ByVal sender As Object, ByVal
ppea As PrintPageEventArgs)
Dim index As Integer = 0
Dim grfx As System.Drawing.Graphics = ppea.Graphics
Dim CurrentY As Integer = 125
Dim CurrentX As Integer = 0
Dim intCount As Integer = 0
Dim intLabelCount As Integer = 0
Dim intTotalLabels As Integer = 0
Dim strFarmNo() As String
Dim strFarmName() As String
Dim ItemsPerPage As Single = 0
Dim strFlockNo() As String
intCount = lvActiveFlocks.SelectedItems.Count
For index = lvActiveFlocks.SelectedItems.Count - 1 To 0 Step -1
Do Until ItemsPerPage > 11
If intCount > 0 Then
ReDim strFarmNo(0 To index)
ReDim strFarmName(0 To index)
ReDim strFlockNo(0 To index)
If lvActiveFlocks.SelectedItems.Count > 0 Then
strFarmName(index) =
(lvActiveFlocks.SelectedItems.Item(index).Text)
strFarmNo(index) =
(lvActiveFlocks.SelectedItems.Item(index).SubItems(1).Text)
strFlockNo(index) =
(lvActiveFlocks.SelectedItems.Item(index).SubItems(2).Text)
End If
Barcode2.DataToEncode = strFarmNo(index) &
strFlockNo(index)
Barcode2.ShowText = True
Barcode2.CaptionAbove = strFarmName(index)
Barcode2.BarHeightCM = 1.5
grfx.PageUnit = GraphicsUnit.Millimeter
grfx.PageScale = 1.0F
grfx.DrawString(Me.Text, Me.Font, Brushes.Black, 0, 0)
Barcode2.PaintOnGraphics(grfx, CurrentX, CurrentY)
ItemsPerPage = ItemsPerPage + 1
intCount = intCount - 1
intLabelCount = intLabelCount + 1
If intLabelCount < 3 Then
CurrentX = CurrentX + 1800
Else
CurrentY = CurrentY + 1400
CurrentX = 0
intLabelCount = 0
End If
Else
ItemsPerPage = 12
End If
Loop
If intCount > 0 Then
ppea.HasMorePages = True
ItemsPerPage = 1
CurrentX = 125
CurrentY = 0
Else
ppea.HasMorePages = False
Exit Sub
End If
Next
End Sub
****************************************************