I can't figure out how to read every word from the textbox in the listbox. It is necessary that when a word is entered in the textbox it is entered into the listbox right away.
Closed due to the fact that the question is not clear to the participants of AK ♦ , Regent , Yuri , cheops , rjhdby 25 Jan '17 at 6:41 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
1 answer
If I understood the question correctly and your application belongs to the "Windows Forms" type, then this task can be solved using the Split () method, the String class.
You need to make a KeyPress event for the TextBox element, in whose processing you want to place a test for pressing the spacebar. When this event triggers, you convert your string to an array, the criterion for separating elements in the array will be a space (which is specified in the parameters of the Split () method).
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) // событие KeyPress Вашего TextBox { if (e.KeyChar == (char) Keys.Space) // Проверяете нажатую клавишу, если это пробел - выполняется код в теле if { listBox1.Items.Clear(); //очищаете элементы Вашего ListBox AddToList(); // И добавляется туда все введенные слова с Вашего TextBox. } } And then you will need every time you press the spacebar (the implementation of this method may vary, depending on your needs, this is just one example) to clean your ListBox and put there all the words written through the space.
private void AddToList() { var wordsArray = textBox1.Text.Split(' '); // Критерий для разбиения Вашей строки в массиве. foreach (var word in wordsArray) { listBox1.Items.Add(word); } }
WinFormsorWPF? - user227049