public void ByteData_TextChanged(object sender, EventArgs e)
{
    DataString.Append(ByteData.Text);
    //here I do some logic on the character just received
 }

I am using a single textbox (ByteData) to input some ASCII characters.
The character strings vary from one character to about five.
I would like to terminate the data entry with a carriage
return (Enter) key and go to another part of the program.
My problem is that the Enter key is not seem to be recognized
and all get is the "beep" tone. How does this snippet recognize
the Enter key so that I can transfer control somewhere else?
Alan

Edited 3 Years Ago by Dani: Formatting fixed

TextChnaged event will not fire while pressing Enter key (carriage return).
To get this key pressed, you have to consider of using any of KeyPress events, like:
KeyDown:

c

or here is another option:

private void ByteData_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
    if (e.KeyChar == (char)13)
    {
         // Then Enter key was pressed
    }
}

If you still want to run the next code from TextChanged event, you can do something like:

private bool bFlag;
public void ByteData_TextChanged(object sender, EventArgs e)
{
     DataString.Append(ByteData.Text);
     if(bFlag)
     {
          //do your code in here after Enter key is pressed
     }
}

private void ByteData_KeyDown(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Enter)
    {
        bFlag = true;       
    }
}

... but this is a lame way to do coding.
I would prefer to call the method (with additional code) directly from KeyDown event, when Enter key is pressed.

Hope it helps,
bye

This question has already been answered. Start a new discussion instead.