By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 974 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Windows Dialog does not handle keydown event Enter or Return

P: n/a
I am building an application that will receive input from a barcode
scanner. The barcode scanner is configured to append to the front
value a single character and hyphen that identify the barcode
standard, then the value in the barcode, terminated by a return. The
barcode scanner appears to the operating system as a USB keyboard.

I am loading the barcode value into a textbox both on my Form1 and on
a dialog box where the user has to make a decision and scan a keyword
barcode to indicate their decision.

The following code does exactly what I want on Form1, but never sees
key values for Enter or Return on the dialog. I am calling the dialog
with ShowDialog (I want form1 to halt until the user makes this
decision).

Even when debugging, I can pound on the enter key on the regular
keyboard, and the keydown is never accepted by Dialog1. Is there some
special property of Enter that it always goes to form1 or a parent of
a dialog?

As a workaround, I am using the TextChanged event and looking for the
exact strings. This sends the remaining Enter keydown from the
barcode scan back to Form1, which I'm attempting to trap, but it's a
kludge, and makes for slightly different behavior whether I have the
barcode scanner on or am doing a keyboard based demo.

I saw one other post about a slightly different issue, but similar in
that an Enter key value, ostensibly for the second form, was flowing
back to the first form.

Any advice?

Thanks,
Keith

Private Sub TextBox1_Keydown(ByVal sender As System.Object, ByVal
e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Return Then
Label2.Text = "Scan value: " + TextBox1.Text
If UCase(Trim(TextBox1.Text)) = "W-SENDQC" Then
Me.DialogResult =
System.Windows.Forms.DialogResult.Abort
Me.Close()
ElseIf UCase(Trim(TextBox1.Text)) = "W-OK" Then
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
Else
Label2.Text = "Scan value: " + TextBox1.Text + " is
not OK or QC!"

End If
Else
Label2.Text = "Scan value: " + TextBox1.Text + " is not OK
or QC!"
End If
End Sub

Apr 24 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Does one of your buttons have a dialog result, i.e "OK"? Windoze will
preview the key and automatically "OK" your form on return or enter if it
does. Same with cancel and escape.
"kgerritsen" <ki***@drexel.eduwrote in message
news:11*********************@r3g2000prh.googlegrou ps.com...
>I am building an application that will receive input from a barcode
scanner. The barcode scanner is configured to append to the front
value a single character and hyphen that identify the barcode
standard, then the value in the barcode, terminated by a return. The
barcode scanner appears to the operating system as a USB keyboard.

I am loading the barcode value into a textbox both on my Form1 and on
a dialog box where the user has to make a decision and scan a keyword
barcode to indicate their decision.

The following code does exactly what I want on Form1, but never sees
key values for Enter or Return on the dialog. I am calling the dialog
with ShowDialog (I want form1 to halt until the user makes this
decision).

Even when debugging, I can pound on the enter key on the regular
keyboard, and the keydown is never accepted by Dialog1. Is there some
special property of Enter that it always goes to form1 or a parent of
a dialog?

As a workaround, I am using the TextChanged event and looking for the
exact strings. This sends the remaining Enter keydown from the
barcode scan back to Form1, which I'm attempting to trap, but it's a
kludge, and makes for slightly different behavior whether I have the
barcode scanner on or am doing a keyboard based demo.

I saw one other post about a slightly different issue, but similar in
that an Enter key value, ostensibly for the second form, was flowing
back to the first form.

Any advice?

Thanks,
Keith

Private Sub TextBox1_Keydown(ByVal sender As System.Object, ByVal
e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Return Then
Label2.Text = "Scan value: " + TextBox1.Text
If UCase(Trim(TextBox1.Text)) = "W-SENDQC" Then
Me.DialogResult =
System.Windows.Forms.DialogResult.Abort
Me.Close()
ElseIf UCase(Trim(TextBox1.Text)) = "W-OK" Then
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
Else
Label2.Text = "Scan value: " + TextBox1.Text + " is
not OK or QC!"

End If
Else
Label2.Text = "Scan value: " + TextBox1.Text + " is not OK
or QC!"
End If
End Sub

Apr 24 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.