-2

I got the following problem

Code:

void textBox1_KeyDown(object sender, KeyEventArgs e)
{
     if (e.KeyCode == Keys.Enter)
     {
         byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox1.Text + "$");
         serverStream.Write(outStream, 0, outStream.Length);\
         serverStream.Flush();
         textBox1.Clear();
     }
 }

the code seems to be right, must be when i press enter it should get the function, but when i press enter (or when i replace to any other key) it just makes a horrible sound in my windows form.

when I get this command in a button:

Code:

 private void button1_Click(object sender, EventArgs e)          
 {
     byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox1.Text + "$");
     serverStream.Write(outStream, 0, outStream.Length);
     serverStream.Flush();
     textBox1.Clear();   
}

then there is no problem. I really need help I dont know why it is. it must be something with like my Windows form dont know the keys im pressing.

Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105
  • First of all: Set a breakpoint in your routine and see if it is hit. Second: Wire all Key* Events to some dummy EventHandler and see which come through. The Textbox may consume some events. – DrKoch Dec 18 '14 at 11:03

1 Answers1

0

Check if you registered the handler in the object settings.

Kia
  • 301
  • 3
  • 11