Solved

Print Screen function

Posted on 2008-06-23
6
2,163 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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