Question : Make screen captcher ralative to the form not the screen

Hi Experts,

The attached code performs a screen captcher of a 55x19 pixel image located at 898,77 on the screen. Is there a way to make the co-ords of the captcher relative to the application's WinForm rather than the screen so the WinForm can be placed anywhere on the screen and captcher the image.
The image is located in a WebBrowser control located on the WinForm.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Private Sub DownloadImage()

            Dim bounds As New Rectangle(0, 0, 55, 19)
            Dim screenshot As System.Drawing.Bitmap
            Dim graph As Graphics

            screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            graph = Graphics.FromImage(screenshot)

            graph.CopyFromScreen(898, 77, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
            PictureBox1.Image = screenshot
            screenshot.Save("Image.bmp")

            Application.DoEvents()

    End Sub

Answer : Make screen captcher ralative to the form not the screen

Try this. I hope it will work for you.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
'Create the empty bitmap
        Dim desiredWidth As Integer = 55
        Dim desiredHeight As Integer = 19
        Dim screenshot As System.Drawing.Bitmap = New System.Drawing.Bitmap(desiredWidth, desiredHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb)

        'Get a handler for the bitmap graphics in order to operate in it
        Dim graph As Graphics = Graphics.FromImage(screenshot)

        'Get the absolute position in screen coordinates of the control we want to capture
        Dim controlPoint As New Point(0, 0)
        controlPoint = Me.WebBrowser1.PointToScreen(controlPoint)
        'What we have done this is: transform the 0,0 coordinate relative to Webbrowser
        'control into an absolute screen coordinate.

        'Capture
        graph.CopyFromScreen(controlPoint.X, controlPoint.Y, 0, 0, New Size(desiredWidth, desiredHeight), CopyPixelOperation.SourceCopy)

        'Save the image
        screenshot.Save("c:\basura\Image.bmp")

        'Free memory retained by objects
        graph.Dispose()
        screenshot.Dispose()

        'And that's all
        Application.DoEvents()
Random Solutions  
 
programming4us programming4us