Printdocument y Hasmorepages

25/10/2004 - 12:33 por Ricard | Informe spam
De momento, gracias por leer el mensaje.

Estoy utilizando el Printdocument (VB-2002) para realizar una serie de
informes y en uno muy simple, estoy parado poque no entiendo qué está
sucediendo.

Lo que me está sucediendo es que no cambia en la primera página, cambia al
finalizar la segunda, con lo que se mezcla la información de la 1ª con la 2ª,
la 3ª con la 4ª, ...

Se que pasa por la rutina de cabecera cada vez, ya que desplazo un texto x
posiciones cada vez que pasa por la rutina, quiere decir que si reconoce el
hasmorepages, ¿Pero, por qué no empieza en la siguiente página? ¿Qué estoy
haciendo mal?


Otra cosa, estoy intentando controlar el salto de página por la altura de
los rectangulos con los que imprimo cada valor, pero no me está funcionando,
no entiendo que unidades o valores se están utilizando, si me lo puedes
explicar, mas gracias.


Saludos,
Ricardo Orduña

Aquí está el código:

#Region "Rutinas de Impresion"
Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnImprimir.Click
Impresion()
'salta = 1
End Sub
Private Sub Impresion()
PrDc = New PrintDocument()
AddHandler PrDc.PrintPage, AddressOf Me.PrDc_PrintPage

PrPrDl = New PrintPreviewDialog()
PrDl = New PrintDialog()
PrDc.DocumentName = "Relación de Datos"
PrDl.Document = PrDc
mm = 0
iFilaActual = 0
iTotalPaginas = 0
iPagina = 0
iPrX = 0
iPrY = 0
iMaxX = 0
iMaxY = 0
iMinX = 0
iMinY = 30

If PrDl.ShowDialog(Me) = DialogResult.OK Then
salta = 1
DefineColumnasListado()
With PrDc
.DefaultPageSettings =
PrDl.PrinterSettings.DefaultPageSettings
.PrinterSettings = PrDl.PrinterSettings
.PrintController = PrDl.Container
.Site = PrDl.Site
End With
With PrPrDl
.Document = PrDc
.AutoScrollMargin = New System.Drawing.Size(0, 0)
.AutoScrollMinSize = New System.Drawing.Size(0, 0)
.ClientSize = New System.Drawing.Size(400, 300)
.Document = PrDc
.Enabled = True
.Icon = CType(Me.Icon, System.Drawing.Icon)
.Location = New System.Drawing.Point(291, 8)
.MaximumSize = New System.Drawing.Size(0, 0)
.Name = PrDc.DocumentName
.Opacity = 1
.TransparencyKey = System.Drawing.Color.Empty
'.Visible = False
End With
PrDc.Site = PrDl.Site
PrPrDl.WindowState = FormWindowState.Maximized
iMaxY = PrDc.DefaultPageSettings.PaperSize.Height
iMaxX = PrDc.DefaultPageSettings.PaperSize.Width
PrPrDl.ShowDialog(Me)
End If

End Sub

Private Sub PrDc_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrDc.PrintPage
Proceso(sender, e)
End Sub
Private Sub proceso(ByRef sender As System.Object, ByRef e As
System.Drawing.Printing.PrintPageEventArgs)
If salta > 0 Then
' e.HasMorePages = True
salta = 0
End If
e.Graphics.PageUnit = GraphicsUnit.Millimeter

iMaxY = e.MarginBounds.Height
'PrG = e.Graphics
Cabecera(sender, e)
Detalle(sender, e)
End Sub
Private Sub Cabecera(ByRef sender As System.Object, ByRef e As
System.Drawing.Printing.PrintPageEventArgs)
Dim k As ImpresionCelda
k = New ImpresionCelda("")
mm += 20
With k
.Alineacion = StringAlignment.Center
.Cabecera = "Cabecera"
.Columna = "MasCabecera"
.CeldaY = 0
.CeldaX = mm
.CeldaAncho = 20
.Size = 10
.CeldaAlto = miAltura
End With

e.Graphics.DrawString(k.Columna, k.Fuente, k.Brocha, k.Celda,
k.CeldaFormato)


End Sub
Private Sub Detalle(ByRef sender As System.Object, ByRef e As
System.Drawing.Printing.PrintPageEventArgs)
Dim a As Single
Dim b As Single
Dim n As Integer
Dim i As Integer = 0
Dim j As Integer = 0

' Defino una celda generica para imprimir

Dim f As ImpresionCelda = New ImpresionCelda("")
iPrY = iMinY
n = 0


For i = iFilaActual To (DV.Count - 1)
n = n + 1
' Para probar cada 6 registros que salte página
If n >= 6 Then
salta = 1
e.HasMorePages = True
Exit For
End If
a = 0
b = 0
gPersona.Columna = gPersona.FormatoTexto(dgSeleccion.Item(i, 0))
f = gPersona
f.CeldaY = iPrY
e.Graphics.DrawString(f.Columna, f.Fuente, f.Brocha, f.Celda,
f.CeldaFormato)
sSize = e.Graphics.MeasureString(f.Columna, f.Fuente,
f.Celda.Size, f.CeldaFormato, 0, 0)
b = Math.Max(f.Celda.Size.Height, b)

a = Math.Max(sSize.Height, a)

gApellido_1.Columna = gPersona.FormatoTexto(dgSeleccion.Item(i,
1))
f = gApellido_1
f.CeldaY = iPrY
e.Graphics.DrawString(f.Columna, f.Fuente, f.Brocha, f.Celda,
f.CeldaFormato)
sSize = e.Graphics.MeasureString(f.Columna, f.Fuente,
f.Celda.Size, f.CeldaFormato, 0, 0)
a = Math.Max(sSize.Height, a)
b = Math.Max(f.Celda.Size.Height, b)

' Hay mas columnas pero lo corto ya que es igual

a = Math.Max(sSize.Height, a)
b = Math.Max(f.Celda.Size.Height, b)
b = f.Celda.Height
' Aquí comparo con la altura para saltar, ahora no pasa
iPrY += b

If iPrY >= iMaxY Then
salta = 1
Exit For
End If

Next
iFilaActual = i + 1

If salta > 0 Then
e.HasMorePages = True
Else
e.HasMorePages = False
iFilaActual = 0
End If
End Sub
#End Region
#Region "Definicion de las columnas de impresion"
Private Sub DefineColumnasListado()
DefPersona()
DefApellido_1()
DefApellido_2()
DefNombre()
DefContrato()
DefAlta()
DefBaja()
DefCategoria()
DefDescripcion()

End Sub

Esto es un ejemplo de como creo una celda para imprimir
Private Sub DefPersona()
gPersona = New ImpresionCelda("")
With gPersona
.Alineacion = StringAlignment.Far
.Cabecera = "Persona"
.CeldaX = 0
.CeldaAncho = 20
.Size = miSize
.CeldaAlto = miAltura
End With

End Sub

Gracias otra vez

Preguntas similare

Leer las respuestas

#1 Ricard
10/11/2004 - 17:23 | Informe spam
Gracias, ya he descubierto que es lo que no entiende vb


"Ricard" escribió:

De momento, gracias por leer el mensaje.

Estoy utilizando el Printdocument (VB-2002) para realizar una serie de
informes y en uno muy simple, estoy parado poque no entiendo qué está
sucediendo.

Lo que me está sucediendo es que no cambia en la primera página, cambia al
finalizar la segunda, con lo que se mezcla la información de la 1ª con la 2ª,
la 3ª con la 4ª, ...

Se que pasa por la rutina de cabecera cada vez, ya que desplazo un texto x
posiciones cada vez que pasa por la rutina, quiere decir que si reconoce el
hasmorepages, ¿Pero, por qué no empieza en la siguiente página? ¿Qué estoy
haciendo mal?


Otra cosa, estoy intentando controlar el salto de página por la altura de
los rectangulos con los que imprimo cada valor, pero no me está funcionando,
no entiendo que unidades o valores se están utilizando, si me lo puedes
explicar, mas gracias.


Saludos,
Ricardo Orduña

Aquí está el código:

#Region "Rutinas de Impresion"
Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnImprimir.Click
Impresion()
'salta = 1
End Sub
Private Sub Impresion()
PrDc = New PrintDocument()
AddHandler PrDc.PrintPage, AddressOf Me.PrDc_PrintPage

PrPrDl = New PrintPreviewDialog()
PrDl = New PrintDialog()
PrDc.DocumentName = "Relación de Datos"
PrDl.Document = PrDc
mm = 0
iFilaActual = 0
iTotalPaginas = 0
iPagina = 0
iPrX = 0
iPrY = 0
iMaxX = 0
iMaxY = 0
iMinX = 0
iMinY = 30

If PrDl.ShowDialog(Me) = DialogResult.OK Then
salta = 1
DefineColumnasListado()
With PrDc
.DefaultPageSettings =
PrDl.PrinterSettings.DefaultPageSettings
.PrinterSettings = PrDl.PrinterSettings
.PrintController = PrDl.Container
.Site = PrDl.Site
End With
With PrPrDl
.Document = PrDc
.AutoScrollMargin = New System.Drawing.Size(0, 0)
.AutoScrollMinSize = New System.Drawing.Size(0, 0)
.ClientSize = New System.Drawing.Size(400, 300)
.Document = PrDc
.Enabled = True
.Icon = CType(Me.Icon, System.Drawing.Icon)
.Location = New System.Drawing.Point(291, 8)
.MaximumSize = New System.Drawing.Size(0, 0)
.Name = PrDc.DocumentName
.Opacity = 1
.TransparencyKey = System.Drawing.Color.Empty
'.Visible = False
End With
PrDc.Site = PrDl.Site
PrPrDl.WindowState = FormWindowState.Maximized
iMaxY = PrDc.DefaultPageSettings.PaperSize.Height
iMaxX = PrDc.DefaultPageSettings.PaperSize.Width
PrPrDl.ShowDialog(Me)
End If

End Sub

Private Sub PrDc_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrDc.PrintPage
Proceso(sender, e)
End Sub
Private Sub proceso(ByRef sender As System.Object, ByRef e As
System.Drawing.Printing.PrintPageEventArgs)
If salta > 0 Then
' e.HasMorePages = True
salta = 0
End If
e.Graphics.PageUnit = GraphicsUnit.Millimeter

iMaxY = e.MarginBounds.Height
'PrG = e.Graphics
Cabecera(sender, e)
Detalle(sender, e)
End Sub
Private Sub Cabecera(ByRef sender As System.Object, ByRef e As
System.Drawing.Printing.PrintPageEventArgs)
Dim k As ImpresionCelda
k = New ImpresionCelda("")
mm += 20
With k
.Alineacion = StringAlignment.Center
.Cabecera = "Cabecera"
.Columna = "MasCabecera"
.CeldaY = 0
.CeldaX = mm
.CeldaAncho = 20
.Size = 10
.CeldaAlto = miAltura
End With

e.Graphics.DrawString(k.Columna, k.Fuente, k.Brocha, k.Celda,
k.CeldaFormato)


End Sub
Private Sub Detalle(ByRef sender As System.Object, ByRef e As
System.Drawing.Printing.PrintPageEventArgs)
Dim a As Single
Dim b As Single
Dim n As Integer
Dim i As Integer = 0
Dim j As Integer = 0

' Defino una celda generica para imprimir

Dim f As ImpresionCelda = New ImpresionCelda("")
iPrY = iMinY
n = 0


For i = iFilaActual To (DV.Count - 1)
n = n + 1
' Para probar cada 6 registros que salte página
If n >= 6 Then
salta = 1
e.HasMorePages = True
Exit For
End If
a = 0
b = 0
gPersona.Columna = gPersona.FormatoTexto(dgSeleccion.Item(i, 0))
f = gPersona
f.CeldaY = iPrY
e.Graphics.DrawString(f.Columna, f.Fuente, f.Brocha, f.Celda,
f.CeldaFormato)
sSize = e.Graphics.MeasureString(f.Columna, f.Fuente,
f.Celda.Size, f.CeldaFormato, 0, 0)
b = Math.Max(f.Celda.Size.Height, b)

a = Math.Max(sSize.Height, a)

gApellido_1.Columna = gPersona.FormatoTexto(dgSeleccion.Item(i,
1))
f = gApellido_1
f.CeldaY = iPrY
e.Graphics.DrawString(f.Columna, f.Fuente, f.Brocha, f.Celda,
f.CeldaFormato)
sSize = e.Graphics.MeasureString(f.Columna, f.Fuente,
f.Celda.Size, f.CeldaFormato, 0, 0)
a = Math.Max(sSize.Height, a)
b = Math.Max(f.Celda.Size.Height, b)

' Hay mas columnas pero lo corto ya que es igual

a = Math.Max(sSize.Height, a)
b = Math.Max(f.Celda.Size.Height, b)
b = f.Celda.Height
' Aquí comparo con la altura para saltar, ahora no pasa
iPrY += b

If iPrY >= iMaxY Then
salta = 1
Exit For
End If

Next
iFilaActual = i + 1

If salta > 0 Then
e.HasMorePages = True
Else
e.HasMorePages = False
iFilaActual = 0
End If
End Sub
#End Region
#Region "Definicion de las columnas de impresion"
Private Sub DefineColumnasListado()
DefPersona()
DefApellido_1()
DefApellido_2()
DefNombre()
DefContrato()
DefAlta()
DefBaja()
DefCategoria()
DefDescripcion()

End Sub

Esto es un ejemplo de como creo una celda para imprimir
Private Sub DefPersona()
gPersona = New ImpresionCelda("")
With gPersona
.Alineacion = StringAlignment.Far
.Cabecera = "Persona"
.CeldaX = 0
.CeldaAncho = 20
.Size = miSize
.CeldaAlto = miAltura
End With

End Sub

Gracias otra vez

email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida