Windows Forms - Impressão
Convertendo um Form em uma Imagem para Impressão
Imports System.Drawing.Printing
Module Imprimir
Dim memoryImage As Bitmap
Private WithEvents printDocument1 As New PrintDocument
'Private Sub printDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printDocument1.PrintPage
' e.Graphics.DrawImage(memoryImage, 0, 0)
'End Sub
''' <summary>
''' esta rotina transforma o form em uma imagem e imprime a imagem em um doc pdf
''' </summary>
Public Sub ImprimirFormComoImagemPDF()
'Dim myGraphics As Graphics = Me.CreateGraphics()
Dim myGraphics As Graphics = frmPrincipal.CreateGraphics()
'Dim s As Size = Me.Size
Dim s As Size = frmPrincipal.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
'memoryGraphics.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, s)
memoryGraphics.CopyFromScreen(frmPrincipal.Location.X, frmPrincipal.Location.Y, 0, 0, s)
'memoryGraphics.CopyFromScreen(Me.Location.X, Me.Location.Y, Me.Location.X + s.Width - 500, Me.Location.Y + s.Height, s)
memoryGraphics.CopyFromScreen(frmPrincipal.Location.X, frmPrincipal.Location.Y, frmPrincipal.Location.X + s.Width - 500, frmPrincipal.Location.Y + s.Height, s)
printDocument1.Print()
End Sub
''' <summary>
''' Exibindo impressoras instaladas
''' </summary>
Public Function ImpressorasInstaladas() As ArrayList
Dim a As New ArrayList
Dim v_total
Dim pd As PrintDocument = New PrintDocument
Dim pkInstalledPrinters As String
a.Clear()
Try
'retornar o numero total de impressoras instaladas
v_total = PrinterSettings.InstalledPrinters.Count
For i = 0 To PrinterSettings.InstalledPrinters.Count - 1
pkInstalledPrinters = PrinterSettings.InstalledPrinters.Item(i)
a.Add(pkInstalledPrinters)
Next
Return a
'seleciona o primeiro item
'Me.Cmb_Impressoras.SelectedIndex = (v_item)
Catch ex As Exception
'exibe mensagem de erro cajo aconteça ao inesperado
MessageBox.Show("Erro da função ImpressorasInstaladas : " + ex.Message)
Return Nothing
Finally
s
'libera da memória
pd.Dispose()
End Try
End Function
End Module