none
Code for capturing form does not work in Windows 10 RRS feed

  • Question

  • I am using VS2010 targeting .Net Framework 4.0.  I have been using the following code to capture my form for years. I just discovered that it does not work on Windows 10 machines.  Works fine on Windows 7 and has for years.  Have any idea on what needs to change for Win 10?  After CaptureScreen() is called, the calling routine either prints memoryImage or places it on the clipboard.  On Win 10, I get a portion of the form and a portion of my desktop.  Appreciate any help I can get on this.

    Private memoryImage as Bitmap   
     Private Sub CaptureScreen()
            Dim myGraphics As Graphics = Me.CreateGraphics()
            Dim s As Size = Me.Size
    
            My.Application.DoEvents()   ' ensure drop downs are hidden b4 capturing image
    
            memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
            Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
            memoryGraphics.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, s)
            myGraphics.Dispose()
            memoryGraphics.Dispose()
        End Sub


    Terry

    Thursday, January 18, 2018 4:40 PM

All replies

  • TerryLa,

    No problem in Windows 10 and VS2017 .Net 4.6 (and 4.0 I tried it extra) so I think your problem is somewhere else in your code.

    By the way, in the VB forums are lately some guys who are very good with graphics, In your case I would visit that forum next time for this kind of questions.

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral


    Success Cor

    • Proposed as answer by Ashidacchi Friday, January 19, 2018 5:44 AM
    Thursday, January 18, 2018 5:24 PM
  • Hi Cor,

    Ok I just did what you did and still not right.  Here is the code followed by what gets put on the clipboard.  As you can see, not getting all the form and sill getting part of my desktop (VS 2010)

    Public Class Form1
        Private memoryimage As Bitmap
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            OnCaptureForm(sender, e)
        End Sub
    
        Private Sub OnCaptureForm(ByVal s As Object, ByVal e As System.EventArgs)
            My.Computer.Clipboard.Clear()
            CaptureScreen()
            My.Computer.Clipboard.SetImage(memoryImage)
            memoryImage.Dispose()
        End Sub
    
        Private Sub CaptureScreen()
            Dim myGraphics As Graphics = Me.CreateGraphics()
            Dim s As Size = Me.Size
    
            My.Application.DoEvents()   ' ensure drop downs are hidden b4 capturing image
    
            memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
            Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
            memoryGraphics.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, s)
            myGraphics.Dispose()
            memoryGraphics.Dispose()
        End Sub


    Terry


    • Edited by TerryLa Thursday, January 18, 2018 6:53 PM
    Thursday, January 18, 2018 6:41 PM
  • Ok, I now see what the problem is (sort of).  I have this new 27 inch 4K monitor and I am scaling the text and app. size.   If I set it back down to the 100% it works just fine - of course I can't see anything that I am doing! lol  It seems to me that these calls to the graphics routines should take any scaling into account.  Know of any way I could do it in code myself?

    Terry

    Thursday, January 18, 2018 6:52 PM