Key Down event is not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • honeyashu
    New Member
    • Jul 2008
    • 11

    Key Down event is not working

    I've created a form in which to add an event to open a chm file on press of F1 i've included a code on keydown event of form but it is not getting fired even i've made the keypreviev property true.....

    [code=vbnet]
    Private Sub frmFacilityDeta ils_KeyDown(ByV al sender As Object, ByVal e As System.Windows. Forms.KeyEventA rgs) Handles MyBase.KeyDown
    Try
    If e.KeyCode = Keys.F1 Then
    Globals.ShowHel pMe(Me)
    End If
    Catch ex As Exception
    MsgBox(ex.Messa ge, MsgBoxStyle.Inf ormation + MsgBoxStyle.OkO nly, Me.Text)
    End Try
    End Sub
    [/code]
  • IanWright
    New Member
    • Jan 2008
    • 179

    #2
    Originally posted by honeyashu
    I've created a form in which to add an event to open a chm file on press of F1 i've included a code on keydown event of form but it is not getting fired even i've made the keypreviev property true.....


    Private Sub frmFacilityDeta ils_KeyDown(ByV al sender As Object, ByVal e As System.Windows. Forms.KeyEventA rgs) Handles MyBase.KeyDown
    Try
    If e.KeyCode = Keys.F1 Then
    Globals.ShowHel pMe(Me)
    End If
    Catch ex As Exception
    MsgBox(ex.Messa ge, MsgBoxStyle.Inf ormation + MsgBoxStyle.OkO nly, Me.Text)
    End Try
    End Sub
    Well I don't use VB, but have you checked that you have added the event handler to the actual form?

    Code:
    frmFacilityDetails.KeyDown += new KeyEventHandler(frmFacilityDetails.frmFacilityDetails);
    or the VB equivalent.

    Comment

    • honeyashu
      New Member
      • Jul 2008
      • 11

      #3
      Originally posted by IanWright
      Well I don't use VB, but have you checked that you have added the event handler to the actual form?

      Code:
      frmFacilityDetails.KeyDown += new KeyEventHandler(frmFacilityDetails.frmFacilityDetails);
      or the VB equivalent.

      Yes i've added the handler 'Handles MyBase.KeyDown' ... this way it is handled in VB.net... thanks but any other suggestion...

      Comment

      • MrMancunian
        Recognized Expert Contributor
        • Jul 2008
        • 569

        #4
        I think the problem is

        Globals.ShowHel pMe(Me)

        Try replacing it with Msgbox("Test") and see if that works. If not, please post the version of VS you're working with.

        Steven

        Comment

        • honeyashu
          New Member
          • Jul 2008
          • 11

          #5
          Originally posted by MrMancunian
          I think the problem is

          Globals.ShowHel pMe(Me)

          Try replacing it with Msgbox("Test") and see if that works. If not, please post the version of VS you're working with.

          Steven
          Globals is a class i've defined to incorporate all global functions... so this is not the problem i think... well this code is working fine with few other forms but in few not........
          Any Suggestions...!

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            I am thinking that something other then the Form object is getting the focus and taking the keydown events and not sharing them with the form.
            Have to checked to see if that function receives any other keys?

            I believe there is also some funkiness if you have F1 set as a neumonic anywhere on the form.

            Comment

            • honeyashu
              New Member
              • Jul 2008
              • 11

              #7
              Originally posted by Plater
              I am thinking that something other then the Form object is getting the focus and taking the keydown events and not sharing them with the form.
              Have to checked to see if that function receives any other keys?

              I believe there is also some funkiness if you have F1 set as a neumonic anywhere on the form.

              as per the code i 've given only F1 key in the limelight & also didnt used it anywhere else.....
              How can i check that focus is going where since debugger is also not activating any event .... and thus i m unable to trace it....

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Hmm, have you tried handles Me.Keydown and not MyBase.KeyDown?

                Comment

                • honeyashu
                  New Member
                  • Jul 2008
                  • 11

                  #9
                  Originally posted by Plater
                  Hmm, have you tried handles Me.Keydown and not MyBase.KeyDown?

                  yes tried so but got the same result...No Response.....

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    What other controls are on the form? Maybe a textbox has the focus?

                    Comment

                    Working...