0

i have code:

private void textEdit_KeyDown(object sender, KeyEventArgs e)
{   //line start
    if (e.KeyCode == Keys.Enter)
    {
        //Do something
        e.SuppressKeyPress = true;
    } //line done

}

when i press enter key, event is fire, after perform something (cursor == line done), i don't know why cursor auto jump to line start and re-perform code in if statement, pls, let me know if u have solution for this issue (prevent auto re-call)

user2314737
  • 27,088
  • 20
  • 102
  • 114
KaKa
  • 133
  • 1
  • 2
  • 9
  • Did you try to check who is the sender of the event? Try to use e.Handled property to prevent double firing. – Michael Jan 20 '14 at 10:44
  • i don't set `e.Handle = false;` because i want re-press enter key after code in line `//Do Somthing` is wrong (show msg) – KaKa Jan 21 '14 at 03:29

1 Answers1

0

A scenario where this can happen, is when the textEdit_KeyDown event handler is subscribed more than once, in other words, the KeyDown event is handled more than once, by the same handler. I suggest you look in your code and comment (if found), one subscription of the textEdit_KeyDown event handler.

//textEdit.KeyDown += textEdit_KeyDown;
SidAhmed
  • 2,332
  • 2
  • 25
  • 46
  • thanks for your advise, but i'm sure textEdit_KeyDown event handler is only once, and it's recall sometime (no always recall) – KaKa Jan 20 '14 at 10:13