How do I close a form which is in a constant loop ?

  • Thread starter Thread starter VBShaper
  • Start date Start date
V

VBShaper

Guest
I can close the form as long as it is not in the loop, but once I place it in the loop I cannot stop it.

Public Class Form1
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwflags As Long)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim InfiniteLoop As Boolean = True

For i = 1 To 45687894
If i = 45687893 And InfiniteLoop = True Then i = 1
Cursor.Position = New Point(200, 200)
Cursor.Position = New Point(400, 400)
Next

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler Me.KeyDown, AddressOf CheckKeyDown
For Each C As Control In Me.Controls
AddHandler C.KeyDown, AddressOf CheckKeyDown
Next
End Sub
Sub CheckKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
If e.KeyCode = Keys.Escape Then
Me.Close()
End If
End Sub
End Class

Continue reading...
 
Back
Top