SaltyDawg Posted March 24, 2008 Posted March 24, 2008 (edited) I have an application in C# which uses a dialog box with a textbox and a button to submit. A barcode scanner is used input the data. Currently after the scan the user must use the mouse to click the submit button. What can I do to submit to data automatically after scanning. I know there is something about a carriage return character, but I have no idea what to do. If I scan the barcode with any other program (even WordPad) it would carriage return to the next line, but its not working in my C# app. Is there something I need to add to my code or a property I need to set to the textbox or button? Thanks. Edited March 24, 2008 by SaltyDawg Quote
Administrators PlausiblyDamp Posted March 24, 2008 Administrators Posted March 24, 2008 Could you not handle the keypress or keyup events for the textbox and if you detect a carriage return then act on it? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
SaltyDawg Posted March 24, 2008 Author Posted March 24, 2008 Could you not handle the keypress or keyup events for the textbox and if you detect a carriage return then act on it? Sounds good. Now how could I detect the carriage return? Quote
techmanbd Posted March 24, 2008 Posted March 24, 2008 Below is the event when doing a kepress And you will also need to change the code in Designer Code for the event handler of the test box private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if(e.KeyChar == 13) { MessageBox.Show("ENTERED");// You code here } } Change this this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); to this this.textBox1.KeyPress += new KeyPressEventHandler(this.textBox1_KeyPress); Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
SaltyDawg Posted March 24, 2008 Author Posted March 24, 2008 the KeyPressEventHandler method is not being recognized. Tried: this.txtScanUserId.KeyPress += new System.KeyPressEventHandler(this.txtScanUserId_KeyPress); By the way, like that Gandhi quote one of my favorites I try to live by. Quote
techmanbd Posted March 24, 2008 Posted March 24, 2008 after "new" take the system out. It is just KeyPressEventHandler Yes, on the quote I heard it one day on Criminal Minds. When they start an episode, they do a famous quote and I heard that. I Have always thought this way, but the quote was the perfect way to say it. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
SaltyDawg Posted March 24, 2008 Author Posted March 24, 2008 Got it: I tried System.Windows.Forms.KeyPressEventHandler and it works. Thanks alot for your help I guess if I had declared "using System.Windows.Forms" it at the top KeyPressEventHandler would have worked Quote
SaltyDawg Posted March 24, 2008 Author Posted March 24, 2008 Yes I read that quote years ago, I was in the Army in Somalia at te time. Quote
techmanbd Posted March 24, 2008 Posted March 24, 2008 Got it: I tried System.Windows.Forms.KeyPressEventHandler and it works. Thanks alot for your help I guess if I had declared "using System.Windows.Forms" it at the top KeyPressEventHandler would have worked AH yes, I have the "using.." at the top. When I start a new program it put it in. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.