Pressing Enter in a textbox

P

Paul Steele

Hi,

I've got a number of textbox's on a windows form in VC++ .NET.
I've got it so that when the user presses [ENTER] whilst in a textbox then
it goes to the next tabstop. This works fine however Windows play the ding
sound as if a invalid key has been pressed. Is there a way to stop this
happening.

Thanks in advance

Paul.
 
G

Guest

I found something in a VB6 app that was upgraded to .NET. This might work,
but I don't really understand why because the behavior of the two handlers
seem to be different than the docs.

Private Sub frmSpecialVisits_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim KeyCode As Short = e.KeyCode
'To trick the system to think
'the Tab key was pressed.
If KeyCode = 13 Then System.Windows.Forms.SendKeys.Send("{TAB}")
End Sub

Private Sub frmSpecialVisits_KeyPress(ByVal eventSender As System.Object,
ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles
MyBase.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
'To eliminate the annoying beep
If KeyAscii = 13 Then KeyAscii = 0
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub

We get no beeps, but, again, I am not entirely sure how this works. It may
be that one of the handlers is not needed, but they were both in there.
 
P

Paul Steele

Cheers for response.

Tried the SendKeys.Send("{TAB}") and e->Handled = true in my Key_Down event,
but it still beeped. :(

So I changed my event from a key_Down to a key_Press and it didn't beep :))

Not quite sure what the difference between a KeyDown and KeyPress event is
though?.


Paul.


mklapp said:
I found something in a VB6 app that was upgraded to .NET. This might work,
but I don't really understand why because the behavior of the two handlers
seem to be different than the docs.

Private Sub frmSpecialVisits_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim KeyCode As Short = e.KeyCode
'To trick the system to think
'the Tab key was pressed.
If KeyCode = 13 Then System.Windows.Forms.SendKeys.Send("{TAB}")
End Sub

Private Sub frmSpecialVisits_KeyPress(ByVal eventSender As System.Object,
ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles
MyBase.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
'To eliminate the annoying beep
If KeyAscii = 13 Then KeyAscii = 0
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub

We get no beeps, but, again, I am not entirely sure how this works. It may
be that one of the handlers is not needed, but they were both in there.

Paul Steele said:
Hi,

I've got a number of textbox's on a windows form in VC++ .NET.
I've got it so that when the user presses [ENTER] whilst in a textbox then
it goes to the next tabstop. This works fine however Windows play the ding
sound as if a invalid key has been pressed. Is there a way to stop this
happening.

Thanks in advance

Paul.
 
G

Guest

Documentation claims one is for printable and one is for unprintable (perhaps
including uprintable).

Paul Steele said:
Cheers for response.

Tried the SendKeys.Send("{TAB}") and e->Handled = true in my Key_Down event,
but it still beeped. :(

So I changed my event from a key_Down to a key_Press and it didn't beep :))

Not quite sure what the difference between a KeyDown and KeyPress event is
though?.


Paul.


mklapp said:
I found something in a VB6 app that was upgraded to .NET. This might work,
but I don't really understand why because the behavior of the two handlers
seem to be different than the docs.

Private Sub frmSpecialVisits_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim KeyCode As Short = e.KeyCode
'To trick the system to think
'the Tab key was pressed.
If KeyCode = 13 Then System.Windows.Forms.SendKeys.Send("{TAB}")
End Sub

Private Sub frmSpecialVisits_KeyPress(ByVal eventSender As System.Object,
ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles
MyBase.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
'To eliminate the annoying beep
If KeyAscii = 13 Then KeyAscii = 0
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub

We get no beeps, but, again, I am not entirely sure how this works. It may
be that one of the handlers is not needed, but they were both in there.

Paul Steele said:
Hi,

I've got a number of textbox's on a windows form in VC++ .NET.
I've got it so that when the user presses [ENTER] whilst in a textbox then
it goes to the next tabstop. This works fine however Windows play the ding
sound as if a invalid key has been pressed. Is there a way to stop this
happening.

Thanks in advance

Paul.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top