Results 1 to 8 of 8

Thread: Escape Key Press Problem !

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108

    Escape Key Press Problem !

    Private Sub Form_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)

    If KeyCode = 27 Then

    MessageBox.Show("You Click The Escape Key")
    Me.currentage_TextBox.Undo()

    End If

    End Sub

    why i click the escape key and it wont work ????

    some one please help me thanx

  2. #2
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Do you have KeyPreview turned on for the form?
    Whadayamean it doesn't work....
    It works fine on my machine!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    yes i turn it on already

    when i press the escape key it didnt show any action

    at the keyPreview there i set to true already
    Last edited by ninjaX; Jul 13th, 2004 at 01:53 PM.

  4. #4
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    you aren't referencing the appropriate objects.

    Try replacing your code with this
    VB Code:
    1. Private Sub frmAbout_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    2.         If e.KeyValue = Keys.Escape Then
    3.             Me.TextBox1.Undo()
    4.         End If
    5.     End Sub
    Whadayamean it doesn't work....
    It works fine on my machine!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    thanx ~
    it works

    i got another problem can you help me to solve ???

    how can i detect which textbox i am using ???

    example i have change the textbox value and i need to undo it how can i know which textbox is change ???

  6. #6
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    this will do the trick
    VB Code:
    1. Private Sub frmAbout_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    2.         If e.KeyValue = Keys.Escape Then
    3.             Dim txtWork As New TextBox
    4.             If Me.ActiveControl.GetType.Equals(txtWork.GetType) Then
    5.                 txtWork = DirectCast(Me.ActiveControl, TextBox)
    6.                 txtWork.Undo()
    7.             End If
    8.         End If
    9.     End Sub
    Whadayamean it doesn't work....
    It works fine on my machine!

  7. #7
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Keep a form level reference object that you set to the sender value of the onChange event for the text box.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    thank you so much !!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width