Считывание с TextBox - C#
Формулировка задачи:
Есть программа которая прорисовывает TextBox в виде кросвордов. В каждый TextBox можно записать только по одной букве которая являеться частью всего слова целиком.
Пользователь должен заполнить кроссворд и нажать на кнопку button1_Click после чего в
ListBox должны переброситься все слова которые пользователь ввел в кроссворд. Пробывала написать
но так оно работать не хочет
Подскажите, пожалуйста, как это правильно сделать.
namespace Crossword { public partial class Form1 : Form { private int numberForDrawingOnTextBox; List<Word> Words = new List<Word>(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { XDocument d = XDocument.Load(@"..\..\Crossword.xml"); int CrossWidth = int.Parse(d.Descendants("Size").First().Attribute(@"width").Value); int CrossHeight = int.Parse(d.Descendants("Size").First().Attribute(@"height").Value); TextBox[,] matrix = new TextBox[CrossWidth, CrossHeight]; foreach (XElement elem in d.Descendants("Word")) { Word w = new Word(); w.Number = int.Parse(elem.Attribute("number").Value); w.Answer = elem.Element("Answer").Value; w.Question = elem.Element("Question").Value; w.X = int.Parse(elem.Element("Location").Attribute("x").Value); w.Y = int.Parse(elem.Element("Location").Attribute("y").Value); w.Horisontal = bool.Parse( elem.Element("Location").Attribute("horisontal").Value); w.Width = int.Parse(elem.Element("Location").Attribute("width").Value); for (int i = 0; i < w.Width; i++) { if(w.Horisontal == true) { if (matrix[w.Y, w.X + i] != null) { w.Letters.Add(i, matrix[w.Y, w.X + i]); } else { TextBox tb = new TextBox() { Width = 21, Visible = true }; w.Letters.Add(i, tb); matrix[w.Y, w.X + i] = tb; } } else { if (matrix[w.Y + i, w.X] != null) { w.Letters.Add(i, matrix[w.Y + i, w.X]); } else { TextBox tb = new TextBox() { Width = 21, Visible = true }; w.Letters.Add(i, tb); matrix[w.Y + i, w.X] = tb; } } } Words.Add(w); } for(int i = 0; i < CrossHeight; i++) { for(int j = 0; j < CrossWidth; j++) { if(matrix[i,j] != null) { TextBox tb = matrix[i, j]; tb.Location = new Point(j*21,i*21); this.Controls.Add(matrix[i, j]); } } } this.ClientSize = new Size(CrossWidth*21, CrossHeight*21); } void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawString(numberForDrawingOnTextBox.ToString(), new Font(FontFamily.GenericSerif, 2), new SolidBrush(Color.Black), new PointF(3, 3)); } } }
private void button1_Click(object sender, EventArgs e) { var w = Words; listBox1.Items.Add(w) }
Решение задачи: «Считывание с TextBox»
textual
Листинг программы
foreach (Word w in Words) { string str = ""; foreach(var Letter in w.Letters) str +=Letter.Value.Text; listbox1.Items.Add(str); }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д