0

I am trying to screen capture in my application please refer with the picture below that has red mark

enter image description here

but it only captures this part

enter image description here

here is the code by the way

Private Function TakeScreenShot(ByVal Control As Control) As Bitmap

    Dim screenSize As Size = New Size(Control.Width, Control.Height)

    Dim screenGrab As New Bitmap(Control.Width, Control.Height)

    Dim g As Graphics = Graphics.FromImage(screenGrab)

    g.CopyFromScreen(New Point(Control.Location.X, Control.Location.Y), Point.Empty, screenSize)

    Return screenGrab

End Function
JeffyO
  • 81
  • 10
  • https://stackoverflow.com/questions/13228185/how-to-configure-an-app-to-run-correctly-on-a-machine-with-a-high-dpi-setting-e – Hans Passant Apr 13 '23 at 08:19

1 Answers1

2

This:

g.CopyFromScreen(New Point(Control.Location.X, Control.Location.Y), Point.Empty, screenSize)

should be this:

g.CopyFromScreen(Control.PointToScreen(Point.Empty), Point.Empty, screenSize)

PointToScreen will convert between the control's coordinate system and screen coordinates. Point.Empty is the origin in any control's coordinate system. This:

Control.PointToScreen(Point.Empty)

is equivalent to this:

Control.Parent.PointToScreen(Control.Location)
jmcilhinney
  • 50,448
  • 5
  • 26
  • 46