keydown event won't fire

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ershn
    New Member
    • May 2007
    • 2

    keydown event won't fire

    Hello.
    I'm writing a windows mobile 2003 project for smartphone in vb.net. Using vs2003 compact framework 1.0. In most attempts on my forms I cannot get the keydown event to fire. I'm basically trying to check and uncheck checkboxes using the number keys. Here is a typical sub I'm using:

    [CODE=vb]Private Sub SelectExCombo_K eyDown(ByVal sender As System.Object, ByVal e As System.Windows. Forms.KeyEventA rgs) Handles MyBase.KeyDown

    If (e.KeyCode = System.Windows. Forms.Keys.Up) Then
    If CheckBox1.Focus ed Then
    Panel1.BackColo r = color.white
    Panel2.BackColo r = Color.Blue
    CheckBox9.Focus ()
    GoTo handled
    ElseIf CheckBox9.Focus ed = True Then
    Panel1.BackColo r = Color.Blue
    Panel2.BackColo r = color.white
    CheckBox1.Focus ()
    GoTo handled
    End If
    End If

    If (e.KeyCode = System.Windows. Forms.Keys.D1) Then
    If CheckBox1.Focus ed Then
    If CheckBox1.Check State = CheckState.Unch ecked Then
    CheckBox1.Check State = CheckState.Chec ked
    ElseIf CheckBox1.Check State = CheckState.Chec ked Then
    CheckBox1.Check State = CheckState.Unch ecked
    GoTo handled
    End If
    ElseIf CheckBox9.Focus ed Then
    If CheckBox9.Check State = CheckState.Unch ecked Then
    CheckBox9.Check State = CheckState.Chec ked
    ElseIf CheckBox9.Check State = CheckState.Chec ked Then
    CheckBox9.Check State = CheckState.Unch ecked
    GoTo handled
    End If
    End If
    End If
    [/CODE]
    Any guidance would be greatly appreciated.
    ershn
    Last edited by RedSon; May 30 '07, 05:01 PM. Reason: Please use CODE tags
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Originally posted by ershn
    Hello.
    I'm writing a windows mobile 2003 project for smartphone in vb.net. Using vs2003 compact framework 1.0. In most attempts on my forms I cannot get the keydown event to fire. I'm basically trying to check and uncheck checkboxes using the number keys. Here is a typical sub I'm using:

    [CODE=vb]Private Sub SelectExCombo_K eyDown(ByVal sender As System.Object, ByVal e As System.Windows. Forms.KeyEventA rgs) Handles MyBase.KeyDown

    If (e.KeyCode = System.Windows. Forms.Keys.Up) Then
    If CheckBox1.Focus ed Then
    Panel1.BackColo r = color.white
    Panel2.BackColo r = Color.Blue
    CheckBox9.Focus ()
    GoTo handled
    ElseIf CheckBox9.Focus ed = True Then
    Panel1.BackColo r = Color.Blue
    Panel2.BackColo r = color.white
    CheckBox1.Focus ()
    GoTo handled
    End If
    End If

    If (e.KeyCode = System.Windows. Forms.Keys.D1) Then
    If CheckBox1.Focus ed Then
    If CheckBox1.Check State = CheckState.Unch ecked Then
    CheckBox1.Check State = CheckState.Chec ked
    ElseIf CheckBox1.Check State = CheckState.Chec ked Then
    CheckBox1.Check State = CheckState.Unch ecked
    GoTo handled
    End If
    ElseIf CheckBox9.Focus ed Then
    If CheckBox9.Check State = CheckState.Unch ecked Then
    CheckBox9.Check State = CheckState.Chec ked
    ElseIf CheckBox9.Check State = CheckState.Chec ked Then
    CheckBox9.Check State = CheckState.Unch ecked
    GoTo handled
    End If
    End If
    End If
    [/CODE]
    Any guidance would be greatly appreciated.
    ershn
    I dont know anything about VB but I do know a bit about WM programming. The way that all windows OSs work is by sending your application messages. I assume that in VB KeyEventArgs is similar to the wParams and lParams that are sent in a C/C++ application. I would think that in order to be in line with the Microsoft framework you would want a sub that is like[CODE=vb] Private Sub HandleExCombo_M essage(ByVal sender As System.Object, ByVal e As System.Windows. Forms.KeyEventA rgs)[/CODE]

    Then you can look at e and sender and figure out what message you need to handle in a large case or if...then chain.

    What other information can you get from the e object?

    Comment

    • ershn
      New Member
      • May 2007
      • 2

      #3
      Thank you for your reply.
      I haven't been able to find any info that allows me to quantify or control e other than passing it as a generic event argument. What is strange is I have written this app for wm5 and it works fine. Also strange is that, while the app does not respond to the down arrow, it does respond to the up arrow key by tabbing throught the checkbox controls in one of the panels. The arrow keys are causing an event to fire but not the sub I have written by hand.

      Comment

      Working...