How can I return the contents of a TextBox when its KeyDown event is fired? I want to make a Console.ReadLine() equivalent. So for example:
Write("Hi! Enter your name..."); Write(ReadFromTextBox());
Is this possible?
You can use the textChanged event.
private void textBox1_TextChanged(object sender, EventArgs e) { Console.WriteLine(textBox1.Text); }
And if you want to read only after the user presses enter:
private void textBox1_KeyDown(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.Enter) MessageBox.Show(textBox1.Text); }
You can use the textChanged event.
And if you want to read only after the user presses enter: