Please I'm new to C#, I created a textBox and a label. What i am expecting is, if I type a value into the textBox, I want it to display on the label and if I change the value it should also change immediately on the label. it work with the code below and i press enter key
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
label1.Text = textBox1.Text;
}
}
But I want it without press Enter/Return Key on keyboard.
Thanks for understanding
This works for VisualStudio
Select your TextBox
in the Designer, go to the it's properties and click on the events (teh icon with the lightning). Then make a double click on the event that is called: TextChanged
.
This creates a new function, that will always be called when the text of your TextBox
changes. Insert following code into the function:
private void textBox1_TextChanged(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
label1.Text = tb.Text;
}
That's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With