I am trying to create two synchronized textboxes using windows forms but I seem to be running into multiple problems. Maybe you guys can help me make things a little more efficient for me.
As you can see, there isn't a problem for the enter key, because I've taken care of that.
- I see a special symbol when I hold the shift key
- Pressing the backspace adds a new symbol to the line.
- Simultaneous pressing of the back key doesn't remove or add(the new symbol) more than once. I assumed the back key would erase 1 character each time it was pressed.
- Back key doesn't erase a new line ("\n\r");
- The last two lines are for the alt and ctrl keys respectively.
The code for this form so far is
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
//Disable usage of arrowkeys
if(e.KeyCode==Keys.Left || e.KeyCode==Keys.Right || e.KeyCode==Keys.Up || e.KeyCode==Keys.Down)
{
e.SuppressKeyPress=true;
}
//Remove a character
if (e.KeyCode == Keys.Back)
textBox2.Text = textBox2.Text.Remove(textBox2.TextLength - 1, 1);
//Upper and lower case characters
if (!e.Shift && e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z)
textBox2.Text += (char)(e.KeyValue + 32);
else
textBox2.Text += (char)(e.KeyValue);
//Next Line
if (e.KeyData == Keys.Enter)
textBox2.Text += "\n\r";
}
What do you suggest I do?
Edit: This isn't my ultimate intent. I wish to convert each input into a different representation, in real time. For now, I am just checking what each input could mean.