' Specifies what happens when the PrintPage event is raised.
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim obj As Bitmap
Dim iData As IDataObject = Clipboard.GetDataObject()
' Determines whether the data is in a format you can use.
If iData.GetDataPresent(DataFormats.Bitmap) Then
obj = iData.GetData(DataFormats.Bitmap)
ev.Graphics.DrawImage(obj, _
obj.GetBounds(System.Drawing.GraphicsUnit.Pixel)) 'ev.Graphics.VisibleClipBounds)
End If
ev.HasMorePages = False
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
'Printscreen
SendKeys.SendWait("%{PRTSC}")
' Assumes the default printer.
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.DefaultPageSettings.Landscape = True
pd.Print()
Catch ex As Exception
MessageBox.Show("An error occurred while printing" & vbCrLf & _
ex.ToString(), "Error")
End Try
End Sub