private void EnterTextBox_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Enter: Button1_Click(this, new EventArgs()); break; case Keys.Up: e.Handled = true; string prevCommand = commands.GetPrevious(); textBox1.Text = prevCommand; textBox1.SelectionStart = prevCommand.Length; break; case Keys.Down: e.Handled = true; string nextCommand = commands.GetNext(); textBox1.Text = nextCommand; textBox1.SelectionStart = nextCommand.Length; break; } }