D
Dan Holmes
I figured out most of it but i don't know what to do with the addhandler
in the constructor.
Public Class ScreenCapture
Dim thisImage As System.Drawing.Image
Dim d As System.Drawing.Printing.PrintDocument
Public Sub New()
d = New System.Drawing.Printing.PrintDocument
AddHandler d.PrintPage, AddressOf PrintPage
End Sub
Public Sub PrintFormClientArea(ByRef f As System.Windows.Forms.Form)
Dim sc As New ScreenCapture
thisImage = sc.CaptureWindow(f.Handle)
d.DocumentName = f.Text
If d.PrinterSettings.InstalledPrinters.Count > 1 Then
Dim p As System.Windows.Forms.PrintDialog = New
System.Windows.Forms.PrintDialog
p.Document = d
p.PrinterSettings.DefaultPageSettings.Landscape = True
If p.ShowDialog(f) = DialogResult.OK Then
d.Print()
End If
Else
d.PrinterSettings.DefaultPageSettings.Landscape = True
d.Print()
End If
End Sub
Private Sub PrintPage(ByVal sender As Object, ByVal ev As
System.Drawing.Printing.PrintPageEventArgs)
ev.Graphics.DrawImage(thisImage, ev.Graphics.VisibleClipBounds)
End Sub
End Class
in the constructor.
Public Class ScreenCapture
Dim thisImage As System.Drawing.Image
Dim d As System.Drawing.Printing.PrintDocument
Public Sub New()
d = New System.Drawing.Printing.PrintDocument
AddHandler d.PrintPage, AddressOf PrintPage
End Sub
Public Sub PrintFormClientArea(ByRef f As System.Windows.Forms.Form)
Dim sc As New ScreenCapture
thisImage = sc.CaptureWindow(f.Handle)
d.DocumentName = f.Text
If d.PrinterSettings.InstalledPrinters.Count > 1 Then
Dim p As System.Windows.Forms.PrintDialog = New
System.Windows.Forms.PrintDialog
p.Document = d
p.PrinterSettings.DefaultPageSettings.Landscape = True
If p.ShowDialog(f) = DialogResult.OK Then
d.Print()
End If
Else
d.PrinterSettings.DefaultPageSettings.Landscape = True
d.Print()
End If
End Sub
Private Sub PrintPage(ByVal sender As Object, ByVal ev As
System.Drawing.Printing.PrintPageEventArgs)
ev.Graphics.DrawImage(thisImage, ev.Graphics.VisibleClipBounds)
End Sub
End Class