Подскажите пожалуйста какой командой можно сделать снимок экрана в VB??
Подскажите пожалуйста какой командой можно сделать снимок экрана в VB??
Код:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
Private Const VK_SNAPSHOT As Short = &H2Cs
Public Function SaveScreen(ByVal theFile As String) As Boolean
Dim data As IDataObject
data = Clipboard.GetDataObject()
Dim bmap As Bitmap
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Bitmap)
Me.PictureBox1.Image = bmap
Me.PictureBox1.Image.Save(theFile, Imaging.ImageFormat.Jpeg)
End If
End Function
Private Sub Command2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command2.Click
Call keybd_event(System.Windows.Forms.Keys.Snapshot, 0, 0, 0)
System.Threading.Thread.Sleep(200) ' To have time to catch the clipboard
SaveScreen("c:\test.jpg")
End Sub
Private Const VK_SNAPSHOT As Short = &H2Cs
Public Function SaveScreen(ByVal theFile As String) As Boolean
Dim data As IDataObject
data = Clipboard.GetDataObject()
Dim bmap As Bitmap
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Bitmap)
Me.PictureBox1.Image = bmap
Me.PictureBox1.Image.Save(theFile, Imaging.ImageFormat.Jpeg)
End If
End Function
Private Sub Command2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command2.Click
Call keybd_event(System.Windows.Forms.Keys.Snapshot, 0, 0, 0)
System.Threading.Thread.Sleep(200) ' To have time to catch the clipboard
SaveScreen("c:\test.jpg")
End Sub
Код:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not SaveScreen(Application.StartupPath & "\screen.png") Then
MessageBox.Show("Sorry dude, couldn't do it.")
End If
End Sub
Public Function SaveScreen(ByVal theFile As String) As Boolean
Try
SendKeys.Send("%{PRTSC}") '<alt + printscreen>
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
If Not SaveScreen(Application.StartupPath & "\screen.png") Then
MessageBox.Show("Sorry dude, couldn't do it.")
End If
End Sub
Public Function SaveScreen(ByVal theFile As String) As Boolean
Try
SendKeys.Send("%{PRTSC}") '<alt + printscreen>
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
Благодарю
Предупреждение 1 Функция "SaveScreen" возвращает значение не для всех путей выполнения. Отсутствует оператор Return?
как ее можно исправить?