473,322 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Windows Dialog does not handle keydown event Enter or Return

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
1 4721
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
0
by: GrantS | last post by:
I need urgent help. Done OK for a newbie getting automation of Windows Messenger into a Winform C# app but have three problems that I urgently need pointers to. Point 1 and 2 are the same issue, I...
0
by: Frans Bouma | last post by:
Hello, It seems VS.NET 2003 locks up itself and the complete shell (mouse locks also) when entering a breakpoint in a special situation. Below is the code to reproduce this behavior. It...
7
by: MounilK | last post by:
Hi all, I am not sure if this is the right NG to post this question. If that's the case please point me to the correct NG. I have a class library(myLib.dll) which has a class(myClass) which has...
8
by: Peter Proost | last post by:
Hi, this is my (simplified) situation: I have got 3 forms and one usercontrol: their names are: container (startup object),myform,another, mycontrol contair has got IsMdiContainer set to...
1
by: rocksoft | last post by:
Hi, I am working in asp.net with C# web application, i have used one textbox and image button for search funtion, i have created one user control for this, but after i have entered...
9
by: pvsundarram | last post by:
hey, i am trying to cancel the keydown event for certain keycodes( for eg:- enter key ).But the cancelling of this event is not happening in firefox. Is there any way to cancel the event in the...
5
by: Stefano Tonello | last post by:
Hi all, I need to call windows' "open with" dialog from my C# windows form application. After the user selects application, control must return to me (I have to launch directly the process). I...
7
by: Sin Jeong-hun | last post by:
I have a dialog form which pops up from the main window using the ShowDialog() method. this dialog has no or button, and it has quite a lot of controls on it. Now, I want to close this dialog...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.