-
February 8th, 2005, 06:10 PM
#1
Return Key in a textbox?
We have scanners which scan a barcode and this barcode is to go into a textbox.
The barcode adds on a returnkey at the end, so I need a way of saying onenter do this...
now I thought a keypress would work, but as no key will be pressed I dont think so anymore.
If anyone could lend a hand here, thanks.
-
February 9th, 2005, 01:51 PM
#2
Re: Return Key in a textbox?
Nobody knows how to do this?
-
February 9th, 2005, 03:03 PM
#3
Re: Return Key in a textbox?
I was thinking of adding an OK button, and a CLEAR button, make the OK the default enter that way when the return is given it should work.
This is a workaround though, id prefer an actual solution.
thanks
-
February 10th, 2005, 03:15 AM
#4
Re: Return Key in a textbox?
Originally Posted by Ctwizzy
We have scanners which scan a barcode and this barcode is to go into a textbox.
The barcode adds on a returnkey at the end, so I need a way of saying onenter do this...
Sorry, but I for one do not actually understand this.
When you scan the barcode, what is it converted into. Text? Numbers? An Image?
Presumably since you said TextBox, it's not the latter. How/ where does the TextBox appear?
What's a 'returnkey'? A 'new line' ascii value?
What do you mean by "onenter"? Presumably the "Enter" key being pressed. Which then brings me back to what does your UI look like.
One thing you'll find in this forum (or any other) is that you will need to be clear about your requirements and if possible provide an example of what is not working.
Useful? Then click on (Rate This Post) at the top of this post.
-
February 10th, 2005, 04:18 AM
#5
Re: Return Key in a textbox?
Hi
not a clear question...
but maybe you need to search for the return / new character in the textbox
you can get the index of the return like this :
textBox1.Text.IndexOf("\r\n");
-
February 10th, 2005, 10:46 AM
#6
Re: Return Key in a textbox?
Return key is the enter key pretty much.
There is a textbox on the main screen, a bar code, which when scanned enteres in a string of numbers. But it is looks like this 123456789-> the -> is a carriage return (i.e enter next line)
We dont want people to be able to manually enter in this barcode and press enter I need to say that when this textbox sees the enter it then will send that string to a method which will do some validation.
So I dont know what kind of event it will be.
As I said earlier having a button for OK isnt really practicle.
What I was thinking is having a non visable button which (im hoping) the enter at the end of the barcode will trigger the OK button, as I know no other way of reacting to the enter.
I hope im being a little bit more clear now?
-
February 10th, 2005, 03:04 PM
#7
Re: Return Key in a textbox?
Hi
I think this code can help...
Call your validation method instead of the messagebox
Code:
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
if(textBox1.Text.Length<3) return;
int nLast=textBox1.Text.IndexOf("\r\n",textBox1.Text.Length-2);
string st;
if(nLast>0)//an enter
{
//get the last entered string
int n=textBox1.Text.LastIndexOf("\r\n",nLast-1);
if(n<0)//the first string
n=0;
else
n+=2;
st=textBox1.Text.Substring(n,nLast-n);
MessageBox.Show(st);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|