Solved

Print Screen function

Posted on 2008-06-23
6
2,155 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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