Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i first time press escape key press one event should trigger when next time escape key press next event should trigger in vb.net
any ideas please
Posted
Comments
Basmeh Awad 6-Feb-14 8:41am    
what have you tried so far???

its simple.. try this
set this Form Property to True from Property Window.
"KeyPreview = True"
VB
Public Class Form1
  Dim EscPressed As Integer = 0

         Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As                 System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Escape Then
            EscPressed += 1
            If EscPressed = 1 Then
                'Your First Event Here
                MessageBox.Show("First")
            ElseIf EscPressed = 2 Then
                'Your Second Event Here
                MessageBox.Show("Second")
            ElseIf EscPressed = 3 Then
                'Your Third Event Here
                MessageBox.Show("Third")
            End If
        End If
       End Sub
End Class
 
Share this answer
 
Not hating on your creativity Basmeh...:-)! A little more complexed way of doing it...

VB
Public Class Form1 
      Dim EscPressed As Integer = 0 
      Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As
                               System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown 

              If e.KeyCode = Keys.Escape Then 
                   Select Case EscPressed 
                        Case 1 : Event1() 
                        Case 2 : Event2() 
                        Case 3 : Event3() 
                   End Select  
              End If 
      End Sub

      Private Sub Event1()
              MessageBox.Show("Event 1 fired") 
              EscPressed += 1 
      End Sub 

      Private Sub Event2()
              MessageBox.Show("Event 2 fired")
              EscPressed += 1 
      End Sub 
     
      Private Sub Event3()
              MessageBox.Show("Event 3 fired")
              EscPressed = 0 End Sub
      End Sub
End Class 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900