CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    204

    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.

  2. #2
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    204

    Re: Return Key in a textbox?

    Nobody knows how to do this?

  3. #3
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    204

    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

  4. #4
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    Re: Return Key in a textbox?

    Quote 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.

  5. #5
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    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");
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  6. #6
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    204

    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?

  7. #7
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    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);
    	}
    }
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured