Solved

Print Screen function

Posted on 2008-06-23
6
2,149 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
6 Comments
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 50 total points
Comment Utility
0
 
LVL 19

Assisted Solution

by:Stephen Manderson
Stephen Manderson earned 50 total points
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Accepted Solution

by:
Rem earned 200 total points
Comment Utility
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
Comment Utility
' 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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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 …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now