Visual Basic.NET - Problemas de impresión: hasmorepages

 
Vista:

Problemas de impresión: hasmorepages

Publicado por Programador (1 intervención) el 28/11/2005 04:47:59
Saludos,

Tengo cierto inconveniente con la impresión de más de una página en .NET, yo estoy utilizando el objeto PrintDocument y PrintDialog, valiéndome de estos busco imprimir, según sea el caso, listados que generen x cantidad de hojas, sin embargo, cuando pretendo imprimirlas en el evento printpage del printdocument, este me genera la cantidad de hojas deseadas, pero con el contenido superpuesto (todo impreso en una misma hoja x cantidad de veces). Aqui publico el código para quien quiera echarme una mano...

Gracias de antemano...

Private Sub Pdc_Empleados_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles Pdc_Empleados.PrintPage

' Establecer márgenes
e.PageSettings.Margins.Bottom = 0
e.PageSettings.Margins.Left = 0
e.PageSettings.Margins.Right = 0
e.PageSettings.Margins.Top = 0

' Esta empieza proceso de impresión

Dim i, PosX, PosY As Integer
Dim mTextSize As System.Drawing.SizeF
Dim Fuente As New System.Drawing.Font("Tahoma", 12, FontStyle.Bold)
Dim TamaTexto As Integer
Dim BlackPen As New Pen(Color.Black, 1)
Dim DrawBrush As New SolidBrush(Color.Black)

'e.Graphics.DrawString("Primera Linea", Fuente, DrawBrush, 50, 100)
'e.HasMorePages = True
'If actualpagina = 1 Then
' If MsgBox("Imprimir la segunda linea", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
' actualpagina += 1
' Exit Sub
' End If
'End If
'e.Graphics.DrawString("Segunda Linea", Fuente, DrawBrush, 100, 100)

'If actualpagina = lastPagina Then e.HasMorePages = False
'actualpagina += 1

mTextSize = e.Graphics.MeasureString("LISTADO DE EMPLEADOS ACTIVOS", Fuente)
TamaTexto = mTextSize.Width

' Imprimir Título
With Pdc_Empleados.DefaultPageSettings
PosX = (.PaperSize.Width / 2) - (TamaTexto / 2)
PosY = 30
e.Graphics.DrawString("LISTADO DE EMPLEADOS ACTIVOS", Fuente, DrawBrush, PosX, PosY)
PosX = 0 : PosY = 0
End With

' Imprimir Empleados
With Grd_Empleados

Dim Cont As Integer ' Variable que controlan No de Empleados por Página
Dim Punto1 As Point : Dim Punto2 As Point

PosY = 82
For i = 0 To .RowsCount - 1

' validar que empleado no esté retirado
If BuscarEstadoEmp(.Item(i, 1).Value) <> "RETIRADOS" Then

Cont = Cont + 1

' Si los registros de empleados rebasan el No de líneas permitidas, Iniciar nueva
If Cont > 52 Then ' sólo 52 registros por línea
' Línea anterior
Punto1 = New Point(26, PosY - 20) : Punto2 = New Point(820, PosY - 20) : e.Graphics.DrawLine(BlackPen, Punto1, Punto2)
' Línea siguiente
PosY = PosY + 18
Punto1 = New Point(26, PosY - 20) : Punto2 = New Point(820, PosY - 20) : e.Graphics.DrawLine(BlackPen, Punto1, Punto2)
' Imprimir Pie de página
Fuente = New Font("Tahoma", 8, FontStyle.Regular)
e.Graphics.DrawString("MODULO DE CCS " & Proc_Conex.DateNow & " - " & Proc_Conex.TimeNow, Fuente, DrawBrush, 28, 1065)
e.Graphics.DrawString("Página " & Me.actualpagina & " de " & Me.lastPagina & ".", Fuente, DrawBrush, 723, 1065)
actualpagina += 1
e.HasMorePages = True '(actualpagina <= lastPagina) 'e.HasMorePages = True ': e.HasMorePages = False
If actualpagina > lastPagina Then e.HasMorePages = False
'Exit Sub
PosY = 102
Cont = 1
End If

Punto1 = New Point(26, PosY - 20)
Punto2 = New Point(820, PosY - 20)
' Línea Horizontal
If i > 0 Then
e.Graphics.DrawLine(BlackPen, Punto1, Punto2)
' Lineas Verticales por Empleado
e.Graphics.DrawLine(BlackPen, 26, PosY - 20, 26, PosY + 20)
e.Graphics.DrawLine(BlackPen, 326, PosY - 20, 326, PosY + 20)
e.Graphics.DrawLine(BlackPen, 426, PosY - 20, 426, PosY + 20)
e.Graphics.DrawLine(BlackPen, 476, PosY - 20, 476, PosY + 20)
e.Graphics.DrawLine(BlackPen, 656, PosY - 20, 656, PosY + 20)
e.Graphics.DrawLine(BlackPen, 820, PosY - 20, 820, PosY + 20)

Fuente = New Font("Tahoma", 9, FontStyle.Regular)
e.Graphics.DrawString(CStr(.Item(i, 0).Value), Fuente, DrawBrush, 28, PosY)
e.Graphics.DrawString(CStr(.Item(i, 1).Value), Fuente, DrawBrush, 328, PosY)
e.Graphics.DrawString(CStr(.Item(i, 2).Value), Fuente, DrawBrush, 428, PosY)
e.Graphics.DrawString(CStr(.Item(i, 3).Value), Fuente, DrawBrush, 478, PosY)
e.Graphics.DrawString(CStr(.Item(i, 4).Value), Fuente, DrawBrush, 658, PosY)
Else
' Sólo aplicables para títulos centrados
Fuente = New Font("Tahoma", 9, FontStyle.Regular)
mTextSize = e.Graphics.MeasureString(UCase(.Item(i, 0).Value), Fuente)
TamaTexto = mTextSize.Width
PosX = (((326 - 26) / 2) + 26) - (TamaTexto / 2)
e.Graphics.DrawString(UCase(.Item(i, 0).Value), Fuente, DrawBrush, PosX, PosY)
mTextSize = e.Graphics.MeasureString(UCase(.Item(i, 1).Value), Fuente)
TamaTexto = mTextSize.Width
PosX = (((426 - 326) / 2) + 326) - (TamaTexto / 2)
e.Graphics.DrawString(UCase(.Item(i, 1).Value), Fuente, DrawBrush, PosX, PosY)
mTextSize = e.Graphics.MeasureString(UCase(.Item(i, 2).Value), Fuente)
TamaTexto = mTextSize.Width
PosX = (((476 - 426) / 2) + 426) - (TamaTexto / 2)
e.Graphics.DrawString(UCase(.Item(i, 2).Value), Fuente, DrawBrush, PosX, PosY)
mTextSize = e.Graphics.MeasureString(UCase(.Item(i, 3).Value), Fuente)
TamaTexto = mTextSize.Width
PosX = (((656 - 476) / 2) + 476) - (TamaTexto / 2)
e.Graphics.DrawString(UCase(.Item(i, 3).Value), Fuente, DrawBrush, PosX, PosY)
mTextSize = e.Graphics.MeasureString(UCase(.Item(i, 4).Value), Fuente)
TamaTexto = mTextSize.Width
PosX = (((820 - 656) / 2) + 656) - (TamaTexto / 2)
e.Graphics.DrawString(UCase(.Item(i, 4).Value), Fuente, DrawBrush, PosX, PosY)
End If
PosY = PosY + 18
End If
Next
If actualpagina > lastPagina Then e.HasMorePages = False
End With

End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder