Está en la página 1de 1

'Cmo imprimir desde Windows Forms en VB.NET Imports System.Drawing.

Printing Public Class Form1 Dim Contenido As PrintPageEventArgs 'representa las propiedades de el docume nto a imprimir, a el asignaremos el texto a imprimir Dim WithEvents Documento As New PrintDocument 'ser el documento a imprimir Dim impresora As New PrintDialog 'representa una instancia del dialogo de co nfiguracin de impresin Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button1.Click 'La funcin DoImpresin() llamar a un dialogo de impresin(seleccionar impresor a, etc.) antes de imprimir If DoImpresion() = True Then Documento.Print() End If End Sub Private Sub Documento_PrintPage(ByVal sender As System.Object, ByVal e As Sy stem.Drawing.Printing.PrintPageEventArgs) Handles Documento.PrintPage Contenido = e ' en la siguiente cadena le asignas el contenido y sus propiedades ' primero le asignamos el texto, segundo el tipo de fuente con su respec tivo tamao, el color, y por ltimo la ubicacin en la pgina Contenido.Graphics.DrawString("*" & Me.TextBox1.Text & "*", New Font("3 of 9 Barcode", 14), Brushes.Black, 50, 300) Contenido.Graphics.DrawString(Me.TextBox1.Text, New Font("Arial", 7), Br ushes.Black, 90, 315) ' esta linea indica que no se imprimirn ms pginas sino slo una Contenido.HasMorePages = False End Sub Private Function DoImpresion() As Boolean impresora.Document = Documento If impresora.ShowDialog() = Windows.Forms.DialogResult.OK Then Documento.PrinterSettings = impresora.PrinterSettings Return True Else Return False End If End Function End Class

También podría gustarte