0

我制作了这个 VB.NET 代码来拍摄整个屏幕的照片,但它只拍摄了焦点区域的照片。为什么是这样?

  Public Function SaveScreen(ByVal theFile As String) As Boolean

            Try
                SendKeys.Send("{PRTSC}")
                Application.DoEvents()

                Dim data As IDataObject = Clipboard.GetDataObject()

                If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
                    Dim bmp As Bitmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Bitmap)
                    bmp.Save(theFile, Imaging.ImageFormat.Png)
                End If
                Clipboard.SetDataObject(0)      'save memory by removing the image from the clipboard
                Return True
            Catch ex As Exception
                Return False
            End Try

        End Function
4

1 回答 1

0

而不是 SendKeys,您可以尝试 API 功能 keybd_event

Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)

Private Const kbdDown = 0
Private Const kbdUp = 2



Private Sub SendKey(ByVal Key As Byte)
    Call keybd_event(Key, 0, kbdDown, 0)
    Call keybd_event(Key, 0, kbdUp, 0)

End Sub

Print-Key 的 Key-Code 为 42 (0x2A)

于 2011-07-06T22:07:14.677 回答