You need to attach an event handler to the TextChanged
event on TextBox1
. This allows you to automatically update the text in TextBox2
when the value of TextBox1
changes.
From there the text is split by the space character to break apart the words in the string and we take the first element in the resulting array, which would be the first word, or null if there were no words at all.
TextBox1.TextChanged += (sender, args) => TextBox2.Text = TextBox1.Text.Split(' ').FirstOrDefault();
1
solved Passing only one word from a TextBox to another TextBox