This is an extension of a previously stated (and solved) problem (Unable to get desired output for keydown c#)
I two textboxes, that have to be synchronized based on what the user types in one of the textboxes.
Now, before you jump into thinking I could simply equate the textboxes, I shall tell you that that isn't my ultimate goal. So, copying text wouldn't work.
The problem:
The text comprises of newline, given by
//Next Line
if (e.KeyData == Keys.Enter)
textBox2.Text += Environment.NewLine;
And when the user presses backspace, it erases the characters using
//Remove a character
if (e.KeyCode == Keys.Back && textBox2.TextLength != 0)
textBox2.Text = textBox2.Text.Remove(textBox2.TextLength - 1, 1);
Simple enough, right? Here's the twist.
Every time I write something in the newline, and erase it to come back to the previous line, in the first textbox, it takes two backspaces to erase the newline and come back to the previous line, in the second textbox.
For example, assume the text is
Hello
Hi
Removing "Hi":
Hello
(The new line still exists, because I haven't yet tried removing it)
Now, if I want to remove the 'o' from "Hello", I'd have to normally press two back spaces and I'd have "Hell" (Which is what happens in the first textbox, where I am typing)
But, by doing so, the text in the second box is still "Hello". It takes me a 3rd backspace to remove 'o'.
At this point, my two textboxes are out of sync, because
Content in first textbox: "Hel"
Content in second textbox: "Hell"
So, please tell me why this is happening? And what I could possibly do to fix it.