Have a try playing around with this code, I got it off the net for a project I was working on
Option Explicit On
Option Strict On
'********************************************************************* *************
' PrintForm Class
'
' Purpose: Print active window
'
' Dependencies:
'
' Author: Øyvind Rustan - Compositae, 27.05.2002
'
www.compositae.no
' Revision:
'
'********************************************************************* *************
Imports System.Windows
Imports System.Drawing
Public Class PrintForm
'------------------------------------------------------------------------------
' New
' Constructor
'------------------------------------------------------------------------------
Public Sub New()
End Sub
'------------------------------------------------------------------------------
' Print
' Print active window (form)
'------------------------------------------------------------------------------
Public Sub Print()
Try
'-- Keys Alt+PrintScreen copies active window to clipboard
Forms.SendKeys.SendWait("%{PRTSC}")
'-- Create print document and printing handler
Dim pd As New Printing.PrintDocument()
AddHandler pd.PrintPage, AddressOf pd_PrintPage
'-- Setup document
pd.DocumentName = "PrintScreen"
With pd.DefaultPageSettings
.Landscape = False
'-- Reduce margins to accomodate larger pictures
.Margins.Left -= .Margins.Left \ 3
.Margins.Top -= .Margins.Top \ 3
.Margins.Right -= .Margins.Right \ 3
.Margins.Bottom -= .Margins.Bottom \ 3
End With
'-- Print document
pd.Print()
Catch ex As Exception
Throw ex
End Try
End Sub
'------------------------------------------------------------------------------
' pd_PrintPage
' PrintPage handler
'------------------------------------------------------------------------------
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As Printing.PrintPageEventArgs)
Try
'-- Get PrintScreen bitmap from clipboard
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData.GetDataPresent(DataFormats.Bitmap) Then
Dim bm As Bitmap = CType(iData.GetData(DataFormats.Bitmap), Bitmap)
'-- Set size of destination rectangle (printer)
Dim rDest As New RectangleF(ev.MarginBounds.Left, ev.MarginBounds.Top, 0, 0)
If bm.Width < ev.MarginBounds.Width Then
'-- Set to bitmap size if bitmap is smaller than paper
rDest.Width = bm.Width
rDest.Height = bm.Height
Else
'-- Set to paper size if bitmap is larger than paper
'-- Scale height to retain proportions
rDest.Width = ev.MarginBounds.Width
rDest.Height = CType(rDest.Width * (bm.Height / bm.Width), Single)
End If
'-- Draw bitmap
ev.Graphics.DrawImage(bm, rDest, bm.GetBounds(GraphicsUnit.Pixel), GraphicsUnit.Pixel)
'-- Draw timestamp
Dim printFont As Font = New Font("Arial", 10, FontStyle.Regular)
ev.Graphics.DrawString(Now.ToString, printFont, Brushes.Black, rDest.Left, rDest.Top + rDest.Height + printFont.GetHeight(ev.Graphics))
Else
'-- No bitmap, cancel printing
ev.Cancel = True
End If
Catch ex As Exception
'-- Cancel printing
ev.Cancel = True
Throw ex
Finally
'-- Print only on page
ev.HasMorePages = False
End Try
End Sub
End Class