Make An Event Occur Once?

Posts 1–4 of 4 · Page 1 of 1
Make An Event Occur Once?
Code:
Public Sub Form1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseHover
        Dim conn As Integer
        If conn = 1 Then
            Stop
        ElseIf conn <> 1 Then
            conn = 1
            Threading.Thread.Sleep(3000)
            Label3.Text = "Connected"
            Label3.ForeColor = Color.Green
        End If
    End Sub
Every time a re-hover the mouse, it still puts the form to sleep for three seconds. can anyone help?



Edit: I did a different code. This one only works one time though. then decides to STOP WORKING!
Code:
Public Sub Form1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseHover
        Dim timeOut As DateTime = Now.AddMilliseconds(3000)
        Do
            Application.DoEvents()
        Loop Until Now > timeOut
        Label3.Text = "jnknoren"
    End Sub
if anyone could fix my old code, it would be lovely
This code will work
Code:
    Public Sub Form1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseHover
        Dim conn As Integer
        If conn <> 1 Then
            conn = 1
            Threading.Thread.Sleep(3000)
            Label3.Text = "Connected"
            Label3.ForeColor = Color.Green
        ElseIf conn = 1 Then
            Stop
        End If
    End Sub
End Class
Quote Originally Posted by Iamazn View Post
This code will work
Code:
    Public Sub Form1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseHover
        Dim conn As Integer
        If conn <> 1 Then
            conn = 1
            Threading.Thread.Sleep(3000)
            Label3.Text = "Connected"
            Label3.ForeColor = Color.Green
        ElseIf conn = 1 Then
            Stop
        End If
    End Sub
End Class
And y does that one work, while my other one doesnt?
Quote Originally Posted by gwentravolta View Post
And y does that one work, while my other one doesnt?
Well, I really have no idea. BUT I do have a guess

Maybe its because in your code, it will check for "conn" first. its a BIG Maybe
Did that code fix it?
Posts 1–4 of 4 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us