prtsc direct to print

MGASPAR
MGASPAR used Ask the Experts™
on
Hi experts!
I wrote the code:
My.Computer.Keyboard.SendKeys("{PRTSC}", True) in a botton click.
I need code to print direct.
Tks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Depending on how much functionality you need, you can do it quite simply in fact. If you add a PrintDocument to your form, then you can print the image via the PrintDocument's PrintPage event. Here's an example of how:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Computer.Keyboard.SendKeys("{PRTSC}", True)
        Me.PrintDocument1.Print()
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Using screenGrab As Image = My.Computer.Clipboard.GetImage()
            e.Graphics.DrawImage(screenGrab, New Point(100, 100))
        End Using
    End Sub
End Class

Open in new window


And then you get something like this:

Result Screenshot
Do take note that the above code relies on the default printer. You can allow the user to select by adding some of the other print controls, or the user can switch their default printer for printing purposes. For the screenshot above, I used the MS XPS document printer.
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Grrrr....   Wrong screenshot. Corrected below.
untitled.PNG

Author

Commented:
Hi Kaufmed!
Perfect.
Simple, clear and efficient.
Thank you!
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
NP. Glad to help  = )

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial