Hi! I made an appilcation that:
- takes a screenshot (while PrtScr pressed),
- saves it as a file (automatically)
- and at least sends this screenshot to my email (automatically)
but
it works only once and when I press PrtScr second time, the debugger throw the exception at the level of 'BMP.Save ("C:\file.jpg")'. How can I fix it? I'd like it works always while PrtScr pressed and not only once. Please, give me some advice. Thanks ina advance for any help:)
- takes a screenshot (while PrtScr pressed),
- saves it as a file (automatically)
- and at least sends this screenshot to my email (automatically)
but
it works only once and when I press PrtScr second time, the debugger throw the exception at the level of 'BMP.Save ("C:\file.jpg")'. How can I fix it? I'd like it works always while PrtScr pressed and not only once. Please, give me some advice. Thanks ina advance for any help:)
Code:
Imports System.Net.Mail
'To tez dziala, robi zrzut, zapisuje go i wysyla potem'
Public Class Form1
Dim myEmail As New MailMessage
Dim mySMTP As New SmtpClient("smtp.gmail.com")
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Int16
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If GetAsyncKeyState(Keys.PrintScreen) Then
Try
Dim ScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim BMP As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), ScreenSize)
BMP.Save("C:\ekran.jpg") [[[[[[ Here is the problem, but I don't know why ]]]]]]
Catch ex As Exception
End Try
Timer2.Start()
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim myATT As New Attachment("C:\ekran.jpg")
myEmail.From = New MailAddress("csmodelmaker@gmail.com")
myEmail.To.Add("coshju@googlemail.com")
myEmail.Attachments.Add(myATT)
myEmail.IsBodyHtml = True
myEmail.Priority = MailPriority.High
mySMTP.EnableSsl = True
mySMTP.Port = 587
mySMTP.Credentials = New System.Net.NetworkCredential("csmodelmaker@gmail.com", "markusmagcsmm")
mySMTP.Send(myEmail)
Timer2.Stop()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class