Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am made a screen shot program but there is a problem, it is not taking the whole screen

see --> http://prntscr.com/9i2fpd

I used these codes

VB
Public Class Form1

    Function ScreenToPicture(ByVal Location As String) As String

        Try
            Dim currentScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
            Dim ScreenToBitmap As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
            Dim gGraphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(ScreenToBitmap)

            gGraphics.CopyFromScreen(New Point(0, 0), New Point(0, 0), currentScreenSize)
            ScreenToBitmap.Save(Location)

            Return Location

        Catch ex As Exception
            Return ex.Message
        End Try

    End Function

    Private Property Path As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim b As Bitmap = New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height, Imaging.PixelFormat.Format32bppArgb)
        Dim gfx As Graphics = Graphics.FromImage(b)
        gfx.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)

        Path = "C:\Users\" + Environment.UserName + "\Desktop\" + Label1.Text + ".jpg"
        b.Save(Path, Imaging.ImageFormat.Jpeg)

        Label1.Text = Label1.Text + 1
    End Sub
End Class
Posted

1 solution

Check the values in the structure returned by My.Computer.Screen.Bounds. They should match the dimensions of your primary screen resolution. If they don't match, read this thread[^]. It's usually because the DPI setting on your primary monitor isn't set to 100% and your code isn't "DPI Aware".
 
Share this answer
 
Comments
Tareq Jami 24-Dec-15 11:00am    
Isn't there another way ?
I mean can't the system just make a screen shot from the whole screen and save it ?

I know a code to make a screen shot, the size doesn't matter with this code

" System.Windows.Forms.SendKeys.Send("{PRTSC}") "

I can use this code to make a screen shot but i dont know how to save it
Dave Kreskowiak 24-Dec-15 15:26pm    
How cute. Someone else who thinks that the system provides every function they would ever need.

NO. There is nothing that will do this for you. YOU have to provide the code to make your code "DPI Aware".

The "stuffing the keyboard" technique you found will do that, but it only does the exact same thing as if you hit the PrtScn key yourself, take snapshot and put it on the clipboard. If you want to take the "easy and less flexible" way out, fine. That's up to you. If you really want to learn how the system works and how to write the code to do it yourself, read the discussions on the link I posted.
Tareq Jami 25-Dec-15 3:00am    
ok >.>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900