I am using Visual Studio 2019 (2022 messes up even more) with Visual Basic .NET framework 3.5 (3.7.2 gives even more headaches).

Earlier I could screen capture with
Code:
        
        Dim img As New Bitmap(frm.ClientSize.Width, frm.ClientSize.Height)
        Using gr As Graphics = Graphics.FromImage(img)
            gr.CopyFromScreen(frm.PointToScreen(frm.ClientRectangle.Location), Point.Empty, frm.ClientSize)
        End Using
        img.Save(filename, Imaging.ImageFormat.Png)
But this does not work on my newer computer with 125% scaling. So I have been trying this which does not work:

Code:
    Sub SaveFromScreen(frm As Form, fil As String)

        Dim g As Graphics = frm.CreateGraphics()
        Dim xDpi As Single = g.DpiX
        Dim scrScale As Single = CSng(xDpi) / 96.0

        Dim bmpWidth As Short = frm.ClientSize.Width * scrScale
        Dim bmpHeight As Short = frm.ClientSize.Height * scrScale

        Dim img As New Bitmap(bmpWidth, bmpHeight)

        Dim scrX1 As Integer = frm.ClientRectangle.Location.X * scrScale
        Dim scrY1 As Integer = frm.ClientRectangle.Location.Y * scrScale

        g.CopyFromScreen(scrX1, scrY1, 0, 0, img.Size, CopyPixelOperation.SourceCopy)
        img.Save(fil & ".png", Imaging.ImageFormat.Png)
        img.Save(fil & ".bmp", Imaging.ImageFormat.Bmp)

    End Sub
Please tell me where I am wrong or how to correct this. Thank you very much for any help.