2

I would like to take a screenshot of a portion of the screen based on coordinates of the left mouse click.

What I can do up to now is get the coordinates with the mouse and show these in a label:

Form1.MousePosition.X and Form1.MousePosition.Y

I get:

X: 369  Y: 256

I want to get the coordinates of a upper left corner and lower right corner and make a screenshot around where the mouse clicked.

IS this possible? How?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Valerio
  • 278
  • 1
  • 6
  • 18

1 Answers1

1

Here is a vb.net program called Capture Screen.

Created By: Masoud (M.D), Submitted on: 6/5/2002 6:16:56 AM:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=309&lngWId=10

Inside the Form1.vb file there is the code to capture a screenshot in VB:

Protected Sub CaptureScreen()
    Dim hSDC, hMDC As Integer
    Dim hBMP, hBMPOld As Integer
    Dim r As Integer

    hSDC = CreateDC("DISPLAY", "", "", "")
    hMDC = CreateCompatibleDC(hSDC)

    FW = GetDeviceCaps(hSDC, 8)
    FH = GetDeviceCaps(hSDC, 10)
    hBMP = CreateCompatibleBitmap(hSDC, FW, FH)

    hBMPOld = SelectObject(hMDC, hBMP)
    r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 13369376)
    hBMP = SelectObject(hMDC, hBMPOld)

    r = DeleteDC(hSDC)
    r = DeleteDC(hMDC)

    oBackground = Image.FromHbitmap(New IntPtr(hBMP))
    DeleteObject(hBMP)
End Sub
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Chiwda
  • 1,233
  • 7
  • 30
  • 52