473,390 Members | 865 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,390 software developers and data experts.

Capturing Carriage Return

Hello all,

To help alleviate human error, I'm developing an application that uses a
barcode reader to fill in a value in a TextBox control. The barcode
reader is connected to the PC through the PS2 keyboard jack, so to
Windows, it's essentially just a keyboard. After the reader has
finished reading the barcode, it sends out Ctrl + M (which I *think* is
a carriage return).

To capture the Ctrl + M, I configured an event handler for the
PreviewKeyDown event. In the event handler, I have tried the following:

private void MyTextBox_PreviewKeyDown(object sender,
PreviewKeyDownEventArgs e)
{
// First way I tried
if (e.Control && e.KeyCode == Keys.M)
{
ShowNewDialog();
}

// Second way I tried
if ((int) e.KeyData == (int) (Keys.M | Keys.Control))
{
ShowNewDialog();
}
}

Essentially, both of them do the same thing, but the first one is less
confusing to somebody that reads my code later.

At any rate, the code works --kind of. The problem is that after
ShowNewDialog() returns, the letter "m" shows up in the MyTextBox
control. If I comment out the call to ShowNewDialog(), the letter "m"
never shows up.

Short of an ugly "fix", such as removing the letter "m" after
ShowNewDialog() returns, I'm not sure what else to do. I was hoping
there was a better way of capturing the carriage return that I haven't
thought of.

Any suggestions?

Thank you in advance,

--
Sean
Nov 3 '06 #1
2 4225
Hi,

Any reason for using PreviewKeyDown instead of KeyDown?

If you are using KeyDown you can use the KeyEventArgs.Handled = true to
suppress keys

On Fri, 03 Nov 2006 15:45:52 +0100, senfo
<en**********@yahoo.comI-WANT-NO-SPAMwrote:
Hello all,

To help alleviate human error, I'm developing an application that usesa
barcode reader to fill in a value in a TextBox control. The barcode
reader is connected to the PC through the PS2 keyboard jack, so to
Windows, it's essentially just a keyboard. After the reader has
finished reading the barcode, it sends out Ctrl + M (which I *think* is
a carriage return).

To capture the Ctrl + M, I configured an event handler for the
PreviewKeyDown event. In the event handler, I have tried the following:

private void MyTextBox_PreviewKeyDown(object sender,
PreviewKeyDownEventArgs e)
{
// First way I tried
if (e.Control && e.KeyCode == Keys.M)
{
ShowNewDialog();
}

// Second way I tried
if ((int) e.KeyData == (int) (Keys.M | Keys.Control))
{
ShowNewDialog();
}
}

Essentially, both of them do the same thing, but the first one is less
confusing to somebody that reads my code later.

At any rate, the code works --kind of. The problem is that after
ShowNewDialog() returns, the letter "m" shows up in the MyTextBox
control. If I comment out the call to ShowNewDialog(), the letter "m"
never shows up.

Short of an ugly "fix", such as removing the letter "m" after
ShowNewDialog() returns, I'm not sure what else to do. I was hoping
there was a better way of capturing the carriage return that I haven't
thought of.

Any suggestions?

Thank you in advance,


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 3 '06 #2
Morten Wennevik wrote:
Any reason for using PreviewKeyDown instead of KeyDown?

If you are using KeyDown you can use the KeyEventArgs.Handled = true to
suppress keys
Hi Morten,

That's a good question and I don't have an answer for you. Using the
KeyDown event fixed everything.

Thank you very much!

--
Sean
Nov 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Canes_Rock | last post by:
The information posted at: ...
4
by: Les Juby | last post by:
Can someone please help with a suggestion as to how I can keep the formatting (carriage returns) that the user enters into a memo field and then display that later. I figured I might be able to...
4
by: Josh | last post by:
Hi, I'm using System.Data.DataSet.ReadXml to convert some xml from a webservice to a DataSet. The xml looks like: <?xml version="1.0"...
2
by: Andrew Chanter | last post by:
I have a VBA function that returns a string including "vbcr" (VB Carriage Return) to seperate a list into multiple rows, eg Item1 & vbcr & Item2 & vbcr & Item3 This works as planned in the...
2
by: eagleofjade | last post by:
I am trying to import data from a Word document into an Access table with VBA. The Word document is a form which has various fields. One of the fields is a field for notes. In some cases, this...
2
by: Matt Mercer | last post by:
Hi all, I am having a frustration problem, and I have read about 25 newsgroup postings that do not have a satisfying answer :) The problem appears to be common where carriage returns are lost...
3
by: Dinsdale | last post by:
I have an xml file that is read into an object using serialization. One of the objects has a string field called delimeter that I want to contain a carriage return. Instead of trying to include the...
6
by: shajias | last post by:
Hi, I am having a xml code like this <name> I am having a carriage return here. Second line with carriage return. This is the last line. </name>
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.