Printing Screen to Printer

bpabmeyer

New member
Joined
Jan 28, 2014
Messages
2
Programming Experience
10+
I am having an issue with printing my screen to a printer. The process works properly up to the point to where it cuts off the image. My screen is set to 1680 by 1050 and it seems like I am only getting 1024 by 768 (or something to that effect). Below is the code i am using...

Dim memoryImage As Bitmap



Private Sub printDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawImage(memoryImage, frmMain.Location.X, frmMain.Location.Y)
End Sub


Private Sub PrintScreen()
Dim myGraphics As Graphics = frmMain.CreateGraphics()
Dim s As Size = frmMain.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)


Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
memoryGraphics.CopyFromScreen(frmMain.Location.X, frmMain.Location.Y, 0, 0, s)
End Sub


Thanks for your help, in advance.
 
If you want to copy the whole screen then why are you specifying the size of the form as the size of the image? The Screen class will give you the dimensions of your screen. PrimaryScreen will give you the primary screen and the Bounds of that will give you the whole desktop area.
 
Also, why are you creating two Graphics objects? Use Graphics.FromImage to create a single Graphics object and make sure you dispose it when you're done. Preferably you should create and destroy it with a Using block.
 
I went ahead and rebuilt what I had after the comments, I am attaching my code as to show the complete fix. Thanks for your help.

Private screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)



Private Sub PprintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawImage(screenGrab, 0, 0, My.Computer.Screen.Bounds.Width - 500, My.Computer.Screen.Bounds.Height - 300)
End Sub


Private Sub PrintDocument1_QueryPageSettings(ByVal sender As Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs) Handles PrintDocument1.QueryPageSettings
e.PageSettings.Landscape = True
End Sub



Private Sub PrintScreen()
Dim screenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim g As Graphics = Graphics.FromImage(screenGrab)


g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenSize)
ppcPrint.Document = PrintDocument1
PrintDocument1.Print()
End Sub
 
Back
Top