Private Sub printDocument1_PrintPage(ByVal sender As System.Object, ByVal e
As System.Drawing.Printing.PrintPageEventArgs) Handles
printDocument1.PrintPage
Try
Dim MyFuente As Font
Dim pfc As New PrivateFontCollection()
pfc.AddFontFile(PATH_FONTS & "\" & Me.cbListaFonts.Text)
Dim FontFamilyBarCode As FontFamily
FontFamilyBarCode = pfc.Families(0)
MyFuente = New Font(FontFamilyBarCode, 80)
e.Graphics.DrawImage(Me.pbxTarjeta.Image, 0, 0)
e.Graphics.DrawImage(Me.pbxFirma.Image, 430, 130)
e.Graphics.DrawString(Me.lblValidaHasta.Text, New Font("Arial",
20, FontStyle.Bold), Brushes.Black, 177, 190)
e.Graphics.DrawString(formatbarcode(Me.txtNumeroInicial.Text),
MyFuente, Brushes.Black, 105, 300)
Catch Qex As Exception
MessageBox.Show(Qex.Message, "Seguridad del Sistema",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
El asunto al cual le estoy dando muchas vueltas es poder imprimir el mismo
documento pero segun un rango, ya no de una en una, ojo que en cada
impresion el codigo de barra debe de cambiar, segun el numero de un
contador.
Intente hacerlo de la siguiente manera pero siempre me sale un cuadro de
dialogo donde se incrementa las hojas hasta que le hago click en cancelar,
eso por el e.HasMorePages creo.
Como seria mi codigo o en que estoy cometiendo el error, pues siempre me
imprime una sola pagina con el valor del ultimo contador, es decir reescribe
la impresion sobre la misma hoja.
Private Sub printDocument1_PrintPage(ByVal sender As System.Object, ByVal e
As System.Drawing.Printing.PrintPageEventArgs) Handles
printDocument1.PrintPage
Try
Dim MyFuente As Font
Dim pfc As New PrivateFontCollection()
pfc.AddFontFile(PATH_FONTS & "\" & Me.cbListaFonts.Text)
Dim FontFamilyBarCode As FontFamily
FontFamilyBarCode = pfc.Families(0)
MyFuente = New Font(FontFamilyBarCode, 80)
Dim Contador As Integer = Me.txtCantidad.Text
Dim Posicion As Integer = 0
Dim i As String = "0000005"
While Contador > 0
If Posicion <> 0 Then
Exit While
End If
e.Graphics.DrawImage(Me.pbxTarjeta.Image, 0, Posicion)
e.Graphics.DrawString(CType(Contador, String).PadLeft(7,
"0"), New Font("Arial", 20, FontStyle.Bold), Brushes.Black, 177, 160 +
Posicion)
e.Graphics.DrawImage(Me.pbxFirma.Image, 430, 130 + Posicion)
e.Graphics.DrawString(Me.lblValidaHasta.Text, New
Font("Arial", 20, FontStyle.Bold), Brushes.Black, 177, 190 + Posicion)
e.Graphics.DrawString(formatbarcode(CType(i,
String).PadLeft(7, "0")), MyFuente, Brushes.Black, 105, 300 + Posicion)
Contador = Contador - 1
Posicion = Posicion + 420
End While
If Contador = 0 Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
Catch Qex As Exception
MessageBox.Show(Qex.Message, "Seguridad del Sistema",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Gracias.
Dim
Cantidad As IntegerValorAImprimir =
CType(Me.txtNumeroInicial.Text, Long) + Cantidad If Cantidad = CType(Me.txtCantidad.Text, Integer) + 1 Thene.HasMorePages =
FalseCantidad = 0
Exit Sub End Ifpfc.AddFontFile(PATH_FONTS &
"\" & Me.cbListaFonts.Text) Dim FontFamilyBarCode As FontFamilyFontFamilyBarCode = pfc.Families(0)
MyFuente =
Newe.Graphics.DrawImage(
Me.pbxTarjeta.Image, 0, 0)e.Graphics.DrawImage(
Me.pbxFirma.Image, 430, 130)e.Graphics.DrawString(
Me.lblValidaHasta.Text, New Font("Arial", 20, FontStyle.Bold), Brushes.Black, 177, 190)e.Graphics.DrawString(ValorAImprimir.PadLeft(7,
"0"), New Font("Arial", 20, FontStyle.Bold), Brushes.Black, 177, 150)e.Graphics.DrawString(formatbarcode(ValorAImprimir.PadLeft(7,
"0")), MyFuente, Brushes.Black, 105, 300) 'TODO : 'Grabar a la Base de datos luego de imprimir la Página. Try If FlatGrabar = 1 Then Call GrabaNroTarjetaBaseDatos(ValorAImprimir.PadLeft(7, "0"))MessageBox.Show(
e.HasMorePages =
True End IfCantidad += 1
MessageBox.Show(Qex.Message,
"Seguridad del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End SubPero ahora cuando lanzo el documento en un PrintPreviewDialog, y le doy en el Boton Imprimir del PrintPreviewDialog siempre imprime solo la Ultima Hoja. Te adjunto el codigo completo porque ya no doy con el Problema. Gracias :-)
Imports
System.Drawing.TextImports
System.IOImports
LogicaEmpresarialPublic
Class FrmTab_GenerarTarjeta Public vlQuienAbrio As Integer Public vlNroTarjeta As String Private _Font As Font Private PATH_FONTS As String = "C:\PROYECTO_FINAL\InterfazCliente\Admision\Fonts" 'Private PATH_FONTS As String = ".\Fonts" Private ImpresoraActual As New Printing.PrinterSettings Private Lector As StreamReader Private FlatGrabar As Integer Private Sub FrmTab_GenerarTarjeta_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load TryFlatGrabar = 0
Me.lblTitulo.Text = "Generacion de Tarjetas" Me.lblTitulo.BringToFront() Me.lblValidaHasta.Text = Format(CType(Today.Day & "-" & Today.Month & "-" & Today.Year + 1, Date), "dd/MM/yyyy") Call CargarListaFuentes() Me.cbListaFonts.SelectedIndex = 3 Me.txtNumeroFinal.ReadOnly = True Me.txtNumeroFinal.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFFE2") Me.txtNumeroInicial.ReadOnly = True Me.txtNumeroInicial.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFFE2") Me.MenuImprimir.Enabled = False Me.MenuAyuda.Enabled = False Dim ClsNumeroInicial As New ClsTabTarjeta Me.txtNumeroInicial.Text = CType(ClsNumeroInicial.NumeroInicial, String).PadLeft(7, "0") Me.txtCantidad.Focus()MessageBox.Show(Qex.Message,
KeyAscii =
CShort(SoloNumeros(KeyAscii)) If KeyAscii = 0 Thene.Handled =
True 'MessageBox.Show("Solo ingresa texto Numerico")Cantidad = 0
Dim ClsNuevoNumeroInicial As New ClsTabTarjeta Me.txtNumeroInicial.Text = CType(ClsNuevoNumeroInicial.NumeroInicial, String).PadLeft(7, "0") Me.txtCantidad.Focus() End Sub Private Sub CargarFuente(ByVal fuente As String)pfc.AddFontFile(PATH_FONTS &
FontFamilyBarCode = pfc.Families(0)
_Font =
New Font(FontFamilyBarCode, 40) End Sub Private Sub CargarListaFuentes() Try Dim dir As New DirectoryInfo(PATH_FONTS) 'Dim dir As New DirectoryInfo("F:\Documents and Settings\Administrador\Mis documentos\Visual Studio 2005\Projects\PROYECTO_FINAL\PROYECTO_FINAL\InterfazCliente\Admision\Fonts") If (dir.Exists) Then Dim file As FileInfo()file = dir.GetFiles()
'Si la carpeta esta llena corremos su contenido para cargar fuentes For Each Fonts As FileInfo In file If (Fonts.Extension = ".TTF") ThencbListaFonts.Items.Add(Fonts.Name)
End If Next 'Seleccionamos por defecto una fuentecbListaFonts.SelectedIndex = 0
End If Catch ex As ExceptionMessageBox.Show(ex.Message,
"RVC Soft®") End Try End Sub Private Function formatbarcode(ByVal code As String) As String Dim barcode As String = String.Emptybarcode =
String.Format("*{0}*", code) Return barcode End Function 'Private Sub printDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printDocument1.PrintPageValorAImprimir =
CType(Me.txtNumeroInicial.Text, Long) + Cantidad If Cantidad = CType(Me.txtCantidad.Text, Integer) + 1 Thene.HasMorePages =
FalseCantidad = 0
Exit Sub End Ifpfc.AddFontFile(PATH_FONTS &
"\" & Me.cbListaFonts.Text) Dim FontFamilyBarCode As FontFamilyFontFamilyBarCode = pfc.Families(0)
MyFuente =
Newe.Graphics.DrawImage(
Me.pbxTarjeta.Image, 0, 0)e.Graphics.DrawImage(
Me.pbxFirma.Image, 430, 130)e.Graphics.DrawString(
Me.lblValidaHasta.Text, New Font("Arial", 20, FontStyle.Bold), Brushes.Black, 177, 190)e.Graphics.DrawString(ValorAImprimir.PadLeft(7,
"0"), New Font("Arial", 20, FontStyle.Bold), Brushes.Black, 177, 150)e.Graphics.DrawString(formatbarcode(ValorAImprimir.PadLeft(7,
"0")), MyFuente, Brushes.Black, 105, 300) 'TODO : 'Grabar a la Base de datos luego de imprimir la Página. Try If FlatGrabar = 1 Then Call GrabaNroTarjetaBaseDatos(ValorAImprimir.PadLeft(7, "0"))MessageBox.Show(
e.HasMorePages =
True End IfCantidad += 1
MessageBox.Show(Qex.Message,
"Seguridad del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End SubFlatGrabar = 1
'TODO : 'Agregamos la Configuracion de la Página. Dim TamañoPersonal As New Printing.PaperSize Dim Ancho As Short Dim Alto As ShortAncho =
Short.Parse("655")Alto =
Short.Parse("420")TamañoPersonal =
New Printing.PaperSize("Tarjetas", Ancho, Alto)printDocument1.PrinterSettings = ImpresoraActual
printDocument1.DefaultPageSettings.PaperSize = TamañoPersonal
Cantidad = 0
'printDialog1.Document = printDocument1
'printDocument1.DefaultPageSettings.PrinterSettings.PrintRange.Selection = Printing.PrintRange.CurrentPage 'printDocument1.Print() If printDialog1.ShowDialog() = Windows.Forms.DialogResult.OK ThenprintDocument1.Print()
Me.txtCantidad.Text = "" Me.txtNumeroInicial.Text = "" Me.txtNumeroFinal.Text = "" Me.MenuImprimir.Enabled = False Me.MenuAyuda.Enabled = False Me.txtCantidad.Focus() End If Catch ex As ExceptionMessageBox.Show(ex.Message)
End Try End Sub Private Sub MenuAyuda_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuAyuda.Click TryFlatGrabar = 0
Dim TamañoPersonal As New Printing.PaperSize Dim Ancho As Short Dim Alto As ShortAncho =
Short.Parse("655")Alto =
Short.Parse("420")TamañoPersonal =
New Printing.PaperSize("Tarjetas", Ancho, Alto)printDocument1.PrinterSettings = ImpresoraActual
printDocument1.DefaultPageSettings.PaperSize = TamañoPersonal
Cantidad = 0
'Dim Preview As New PrintPreviewDialog 'Preview.Document = printDocument1 'Preview.MainMenuStrip.Items(0).Enabled = True 'Preview.ShowDialog(Me)printPreviewDialog1.ShowDialog(
Me)MessageBox.Show(Qex.Message,
"Seguridad del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End SubCargarFuente(
Me.cbListaFonts.Text) If (txtNumeroInicial.Text = String.Empty) ThenlbBarCode.Text =
"Tienes que introducir un Código" Else If (Not _Font Is Nothing) ThenlbBarCode.Font = _Font
lbBarCode.Text = formatbarcode(txtNumeroInicial.Text)
lbcode.Text = formatbarcode(txtNumeroInicial.Text)
If Me.txtCantidad.Text.Trim.Length <> 0 Then Me.txtNumeroFinal.Text = CType(CType(Me.txtNumeroInicial.Text, Long) + CType(Me.txtCantidad.Text, Long), String).PadLeft(7, "0") End If End If End If ElseIf Me.txtNumeroInicial.Text.Trim.Length = 0 ThenlbBarCode.Text =
"" Me.txtNumeroFinal.Text = "" End If Catch ex As ExceptionMessageBox.Show(ex.Message,
"RVC Soft®") End Try End Sub Private Sub txtCantidad_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCantidad.KeyPress Try Dim KeyAscii As Short = CShort(Asc(e.KeyChar))KeyAscii =
CShort(SoloNumeros(KeyAscii)) If KeyAscii = 0 Thene.Handled =
True 'MessageBox.Show("Solo ingresa texto Numerico")MessageBox.Show(Qex.Message,
SoloNumeros = 0
ElseSoloNumeros = Keyascii
End If Select Case Keyascii Case 8SoloNumeros = Keyascii
Case 13SoloNumeros = Keyascii
End Select End Function Private Sub txtNumeroFinal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNumeroFinal.KeyPress Try Dim KeyAscii As Short = CShort(Asc(e.KeyChar))KeyAscii =
CShort(SoloNumeros(KeyAscii)) If KeyAscii = 0 Thene.Handled =
True 'MessageBox.Show("Solo ingresa texto Numerico")MessageBox.Show(Qex.Message,
NroTarjetas.GrabaTarjeta(NroTarjeta, Format(Today,
"dd/MM/yyyy"), Variables.vgUsuario, Variables.vgPerfil, Variables.vgIP) End SubEnd
Class
"Leonardo Azpurua [mvp vb]" <l e o n a r d o (arroba) m v p s (punto) o r g> escribió en el mensaje news:%23N2ThSG...@TK2MSFTNGP04.phx.gbl...