Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

G'Day,

 

I have a textbox, and i want to know when the numpad's <enter> button is pressed.

 

I have tried the following:

sub checkkeypressed(byval sender as object, byval e as keypresseventargs) handles tb1.keypress

dim keypressed as string = e.keychar

end sub

and i have also tried

sub checkkeypressed(byval sender as object, byval e as keyeventargs) handles tb1.keydown

dim keypressed as string = e.keyvalue.string

end sub

However, neither of these subs are called when the numpad's <enter> button is pressed (that being the <enter> button that is situated within the numpad.

 

I need to catch when this <enter> button is pressed, rather than when the <return> (acceptbutton) is pressed, because the data entry operators will primarily be using this <enter> key as their <TAB> button so to speak.

 

If anyone can help with this, i would be much appreciated.

 

Also, in case this possibility comes as a response, "No", the numpad's <enter> button does not call the acceptbutton method, only the <return> button does that.

 

Cheers,

 

Michelle

  • Leaders
Posted

try this :

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
   If e.KeyCode = Keys.Enter Then
       MessageBox.Show("Enter Pressed!")
   End If
End Sub

  • *Experts*
Posted (edited)

I dont think there is that possibility because both of them do excatly the same thing and they have both the KeyValue of 13.

[edit]

[/edit]

Sorry I misunderstood your question, I realized it now that I just look at your response.

Edited by mutant
Posted

Hi There,

 

I don't really mind if the <return> or <enter> buttons return the same keyvalue, but my problem is, that when the <enter> button is pressed, it does not fire the event.

 

To make things a little more detailed, this probably will make a difference, although technically it shouldn't. The textbox i am referring to is a datagridtextboxcolumn.textbox.

 

But, i have have defined it this way (in short):

dim colstyle1 as new datagridtextboxcolumn

dim tb1 as new textbox

tb1 = colstyle1.textbox

 

When all(?) other buttons are pressed on the keyboard the event fires, all expect when the <enter> button on the numeric keypad is pressed.

 

Why not??

 

If someone can offer some further assistance, that would be great.

 

Thanks.

  • Leaders
Posted

looks like you may need to add a handler for the new textbox , i just put a quick example together showing a textbox created at runtime reacting to the Enter key :

   Private WithEvents txtBox As TextBox

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim tb As New TextBox()
       tb.Location = New Point(120, 50)
       tb.Visible = True
       Controls.Add(tb)

       AddHandler tb.KeyPress, AddressOf txtBox_KeyPress
   End Sub

   Private Sub txtBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtBox.KeyPress
       If e.KeyChar = Chr(Keys.Enter) Then
           MessageBox.Show("enter pressed")
       End If
   End Sub

Posted

Hi There,

 

As i said, when all other keys are pressed on the keyboard, the event fires, it's only when the numpad's <enter> button is pressed that it doesn't. Therefore, my conclusion is that the event already works ok. The only time the the numpad's <enter> button will fire the event is when you go out of the textbox (cell) and click back in it with the mouse button and then press the numpad's <enter> button.

 

This is obviously not ideal, as the data entry operators will be typing and pressing the numpad's <enter> key to navigate instead of the <tab> button.

 

Is there anything i can do to get the <enter> button to fire the keydown, keyup or keypress event???

 

Thanks again,

Michelle

Posted

Hi,

 

I'm not sure if this may help, but if i have an acceptbutton for the form that does something, and set the tb1.acceptsreturn = false, then is there a way to get the numpad's <enter> button to call this method aswell? I have tried by just adding the method and pressing the numpad's <enter> button, but this still goes to the next row in the datagrid, and therefore does not call the button.click method that has been set by the forms acceptsreturn attribute.

 

Is there a way to get the acceptsreturn method to also be called by the numpad's <enter> button or not?

 

If there is a way of doing this, how could i distinguish between the value of the key pressed between the <return> and the numpad's <enter> key? Is there a way?

 

Please reply as soon as possible.

 

Regards,

Michelle

  • 2 weeks later...
Posted

I am having so much trouble with the notepad part today, I want Numpad4 and 5 to work:

 

Private Sub Getaway_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

       If Control = False Then Exit Sub

       MsgBox("Keys are working")

       If e.KeyChar = Chr(Keys.NumPad4) Then
           MsgBox("Left is working")
           Select Case Placement
               Case 2
                   P2.Visible = False
                   P1.Visible = True
                   Placement = 1
               Case 3
                   P3.Visible = False
                   P2.Visible = True
                   Placement = 2
               Case 4
                   P4.Visible = False
                   P3.Visible = True
                   Placement = 3
               Case 5
                   P5.Visible = False
                   P4.Visible = True
                   Placement = 4
               Case 6
                   P6.Visible = False
                   P5.Visible = True
                   Placement = 5
           End Select
       End If


       If e.KeyChar = Chr(Keys.NumPad6) Then
           Select Case Placement
               Case 1
                   P1.Visible = False
                   P2.Visible = True
                   Placement = 2
               Case 2
                   P2.Visible = False
                   P3.Visible = True
                   Placement = 3
               Case 3
                   P3.Visible = False
                   P4.Visible = True
                   Placement = 4
               Case 4
                   P4.Visible = False
                   P5.Visible = True
                   Placement = 5
               Case 5
                   P5.Visible = False
                   P6.Visible = True
                   Placement = 6
           End Select
       End If
   End Sub

 

The Message Box works but the keys don't :(

 

btw Placement = 4 at the Startup of the Form.

"Reality is fake, Dreams are for real"

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...