This is the code I often use. It should work in windowed mode all the time. But it may not work in a fullscreen mode that has lost focus.
#Region " CaptureScreenshot ... "  
                                                        Public Function CaptureScreenshot(ByVal Filename As String, ByVal ImageFormat As Direct3D.ImageFileFormat) As Boolean  
        Try  
            Dim B As Direct3D.Surface  
                        B = mobjDevice.GetBackBuffer(0, 0, Direct3D.BackBufferType.Mono)  
  
                        Direct3D.SurfaceLoader.Save(Filename, ImageFormat, B)  
            B.Dispose()  
        Catch ex As Exception  
            Return False  
        End Try  
  
        Return True  
    End Function  
  
                                                        Public Function CaptureScreenshot(ByVal Filename As String) As Boolean  
        Return CaptureScreenshot(Filename, Direct3D.ImageFileFormat.Bmp)  
    End Function  
#End Region