Using enter key to tab from numericupdown controls

724 views
Skip to first unread message

jovock

unread,
Aug 2, 2007, 11:57:46 AM8/2/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I have a form that has a bunch of numericupdown controls. I would like
the user to be able to use the enter key to tab to each control.
However whenever the user does this the computer beeps an error sound.

I have looked at other posts and the only thing I could find is
references to a textbox instead of a numericupdown control. They
suggests that I use the e.Handled = True in the keypress event to get
rid of that. However this does not work. Do I have to do something
different with a numericupdown control?

Here is a copy of the code that I am using.

Private Sub UpDown9am_KeyPress(ByVal sender As Object, ByVal e As
KeyPressEventArgs) Handles UpDown9am.KeyPress
If e.KeyChar = ChrW(Keys.Return) Then
SendKeys.Send("{TAB}")
e.Handled = True
End If
End Sub

I am using vb.net in visual studio 2005 on an XP machine.

Zeeshan Zahid

unread,
Aug 3, 2007, 5:49:01 AM8/3/07
to DotNetDe...@googlegroups.com
Instead of using keyPress use KeyDown event, code written below

If e.KeyCode = Keys.Enter Then
SendKeys.Send("{TAB}")
End If

jovock

unread,
Aug 3, 2007, 5:28:28 PM8/3/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Even after changing it to the keydown event I still get the error
sound. Here is a copy of the new code that I am using.

Private Sub UpDown9am_KeyDown(ByVal sender As Object, ByVal e As
KeyEventArgs) Handles UpDown9am.KeyDown


If e.KeyCode = Keys.Enter Then

e.Handled = True


SendKeys.Send("{TAB}")
End If

End Sub

I have also tried taking e.Handled = True out of it and I still get
the same error sound.

> > I am using vb.net in visual studio 2005 on an XP machine.- Hide quoted text -
>
> - Show quoted text -

Zeeshan Zahid

unread,
Aug 4, 2007, 6:34:40 AM8/4/07
to DotNetDe...@googlegroups.com
Ok. Try one more thing, override the ProcessDialogKey and
handle the enter key there. You need to modify it to handle
enter key for button. 

Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
Select Case keyData
Case Keys.Enter
SendKeys.Send("{TAB}")
Return True

Case Else
Return MyBase.ProcessDialogKey(keyData)
End Select
End Function

jovock

unread,
Aug 4, 2007, 12:40:35 PM8/4/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
That works beautifully. Thank you for your help

> > > - Show quoted text -- Hide quoted text -

Ako

unread,
Aug 12, 2007, 6:49:52 AM8/12/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
what about this:

UpDown9am.SelectNextControl
e.SuppressKeyPress = True

Reply all
Reply to author
Forward
0 new messages