[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Print Screen function

Posted on 2008-06-23
6
Medium Priority
?
2,176 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 150 total points
ID: 21849347
0
 
LVL 19

Assisted Solution

by:Stephen Manderson
Stephen Manderson earned 150 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
Technology Partners: 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 600 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 600 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

649 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