Solved

Print Screen function

Posted on 2008-06-23
6
2,160 Views
Last Modified: 2013-11-26
Hello all,

I would like to print screen of my pc.
I would like to click a button and save this into my c:\images\

Could anyone please send me the code for this?
I am using vb.net

Thanks
0
Comment
Question by:nectarios777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 50 total points
ID: 21849347
0
 
LVL 19

Assisted Solution

by:Stephen Manderson
Stephen Manderson earned 50 total points
ID: 21849416
Hi there,

This code here is similar to what I currently use.
http://www.devasp.net/net/articles/display/303.html

Works very well, with little code

Regards
Steve
0
 
LVL 14

Expert Comment

by:rachitkohli
ID: 21852654
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
  bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const VK_SNAPSHOT = &H2C

Public Sub PrintScreen()
    keybd_event VK_SNAPSHOT, 1, 0, 0
End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
Rem earned 200 total points
ID: 21854505
Hi,
Another way....

' -------This snippet,    
Private Sub YOURBUTTON_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YOURBUTTON.Click
        GetScreenSnapshot()
        PreviewData()
End Sub
'-------Handles this (not the cleanest way, but it sure works)
Function GetScreenSnapshot() As Image
        Return GetScreenSnapshot(False)
End Function

Function GetScreenSnapshot(ByVal activeWindowOnly As Boolean) As Image
        ' Alt-Print Screen captures the active window only
        If activeWindowOnly Then
            SendKeys.SendWait("%{PRTSC}")
        Else
            SendKeys.SendWait("{PRTSC 2}")
        End If

        ' return the bitmap now in the clipboard
        Return DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap),  _
            Image)
End Function
   
0
 
LVL 28

Assisted Solution

by:iboutchkine
iboutchkine earned 200 total points
ID: 21854516
' Takes a screenshot of the current application and
' puts the screenshot into a picture box.

' Clear the picture box image
PictureBox2.Image = Nothing

System.Windows.Forms.Application.DoEvents()

' Take a screenshot of the application that has
' focus. The screenshot is on the clipboard.
System.Windows.Forms.SendKeys.Send("%{PRTSC}")

Dim iData As System.Windows.Forms.IDataObject = _
    System.Windows.Forms.Clipboard.GetDataObject()

' Set the picture box's image property to the screenshot
PictureBox2.Image = CType(iData.GetData(System.Windows. _
    Forms.DataFormats.Bitmap), System.Drawing.Image)

System.Windows.Forms.Application.DoEvents()
0
 
LVL 3

Expert Comment

by:Rem
ID: 21854834
Hi,
You can add this if you want to: (the first sub was already referred to in my first post)
   Public Sub PreviewData()

        ' Prepare and show data
        Me.Focus()
        myScreenshot = GetScreenSnapshot(True)

        Me.Visible = False
        dlgPrintPreview.Document = PreparePrintDocument()
        dlgPrintPreview.ShowDialog()
        Me.Visible = True

    End Sub

    Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
        On Error GoTo 0
        Dim margins As New Margins(50, 50, 50, 50)
        PrintDocument1.PrinterSettings.DefaultPageSettings.Landscape = True

        PrintDocument1.DefaultPageSettings.Margins = margins
        e.Graphics.DrawImage(myScreenshot, 30, 30, PrintDocument1.DefaultPageSettings.PaperSize.Width - 60, PrintDocument1.DefaultPageSettings.PaperSize.Height - 650)
        e.HasMorePages = False

    End Sub
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question