I am using vb.net to code. This program goes through each pixel in a picturebox checking and compare the color that the user selected. I made a code to stop the looping when the user press ESC button on the keyboard. But it looks like the program does not stop when the the esc is pressed.
I made a messagebox to pop when the esc button is pressed. When the loop is running and I press the esc button, the messagebox pops up only when the whole loop is done.
For x = rect.X To endPointX - 1 Step pixelStep
For y = endpointY - 1 To rect.Y Step -1
If e.X >= 0 And e.Y >= 0 And (e.X < PictureBox1.Width) And (e.Y < PictureBox1.Height) Then
If escPress Then
Exit For
End If
If bmp.GetPixel(x, y) = cor Then
cruzNoBitmap(PictureBox1, n, pemSize, x, y)
addRow(x, y)
Exit For
End If
End If
Next
If escPress Then
Exit For
End If
Next
Private Sub frmBitmaps_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
MsgBox("test")
escPress = True
End If
End Sub
Any help I would be thankful.