private void openSaveToolStripMenuItem_Click(object sender, EventArgs e) { if (words != null && words.Count != 0) { //обнулить слова foreach (var item in words) { int len = item.Length; item.WordStr = string.Empty; item.Length = len; } words = new List<Word>(); OpenFileDialog openFileDialog = new OpenFileDialog(); Directory.CreateDirectory(Application.StartupPath + "\\saveModel"); openFileDialog.InitialDirectory = Application.StartupPath + "\\saveModel"; openFileDialog.Filter = "model files (*.model)|*.model|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { FileStream file = new FileStream(openFileDialog.FileName, FileMode.Open); BinaryFormatter BF = new BinaryFormatter(); words = (List<Word>)BF.Deserialize(file); width = 999; height = 999; ColumnCount = width / CellSize; RowCount = height / CellSize; tableLayoutPanel1.ColumnCount = ColumnCount; tableLayoutPanel1.RowCount = RowCount; this.tableLayoutPanel1.Size = new System.Drawing.Size(CellSize * ColumnCount + ColumnCount, CellSize * RowCount + RowCount); //отобразить for (int i = 0; i < ColumnCount; i++) { tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, CellSize)); } for (int i = 0; i < RowCount; i++) { tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, CellSize)); } TableClear(); for (int i = 0; i < words.Count; i++) { Dictionary<int, Point> wordP = words[i].WordPoint; foreach (var charP in wordP) { MyGroupBox btn = new MyGroupBox(); btn.Name = charP.Value.X.ToString() + " " + charP.Value.Y.ToString(); if (charP.Key == 0) { btn.Index = (i + 1).ToString(); } if (tableLayoutPanel1.Controls.Find(btn.Name, false).Length == 0) { tableLayoutPanel1.Controls.Add(btn); tableLayoutPanel1.SetCellPosition(btn, new TableLayoutPanelCellPosition(charP.Value.X, charP.Value.Y)); } else if (charP.Key == 0) { ((MyGroupBox)tableLayoutPanel1.GetControlFromPosition(charP.Value.X, charP.Value.Y)).Index = (i + 1).ToString(); } } } ShowWords(words); listBoxQuestion.Items.Clear(); for (int i = 0; i < words.Count; i++) { if (words[i].WordStr != string.Empty) { listBoxQuestion.Items.Add((i + 1).ToString() + " - " + dictionary[words[i].WordStr]); } } } } else { words = new List<Word>(); OpenFileDialog openFileDialog = new OpenFileDialog(); Directory.CreateDirectory(Application.StartupPath + "\\saveModel"); openFileDialog.InitialDirectory = Application.StartupPath + "\\saveModel"; openFileDialog.Filter = "model files (*.model)|*.model|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { FileStream file = new FileStream(openFileDialog.FileName, FileMode.Open); BinaryFormatter BF = new BinaryFormatter(); words = (List<Word>)BF.Deserialize(file); width = 999; height = 999; ColumnCount = width / CellSize; RowCount = height / CellSize; tableLayoutPanel1.ColumnCount = ColumnCount; tableLayoutPanel1.RowCount = RowCount; this.tableLayoutPanel1.Size = new System.Drawing.Size(CellSize * ColumnCount + ColumnCount, CellSize * RowCount + RowCount); //отобразить for (int i = 0; i < ColumnCount; i++) { tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, CellSize)); } for (int i = 0; i < RowCount; i++) { tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, CellSize)); } for (int i = 0; i < words.Count; i++) { Dictionary<int, Point> wordP = words[i].WordPoint; foreach (var charP in wordP) { MyGroupBox btn = new MyGroupBox(); btn.Name = charP.Value.X.ToString() + " " + charP.Value.Y.ToString(); if (charP.Key == 0) { btn.Index = (i + 1).ToString(); } if (tableLayoutPanel1.Controls.Find(btn.Name, false).Length == 0) { tableLayoutPanel1.Controls.Add(btn); tableLayoutPanel1.SetCellPosition(btn, new TableLayoutPanelCellPosition(charP.Value.X, charP.Value.Y)); } else if (charP.Key == 0) { ((MyGroupBox)tableLayoutPanel1.GetControlFromPosition(charP.Value.X, charP.Value.Y)).Index = (i + 1).ToString(); } } } ShowWords(words); listBoxQuestion.Items.Clear(); for (int i = 0; i < words.Count; i++) { if (words[i].WordStr != string.Empty) { listBoxQuestion.Items.Add((i + 1).ToString() + " - " + dictionary[words[i].WordStr]); } } } } }
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { //words.Clear(); words = new List<Word>(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = Application.StartupPath + "\\crossModel"; openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { FileStream file = new FileStream(openFileDialog.FileName, FileMode.Open); StreamReader streamReader = new StreamReader(file, ASCIIEncoding.Default); string crossStr = string.Empty; string[] crossParam; try { crossStr = streamReader.ReadLine(); streamReader.Close(); crossParam = Regex.Split(crossStr, ","); string[] whStr = Regex.Split(crossParam[0], " "); width = int.Parse(whStr[0]); height = int.Parse(whStr[1]); ColumnCount = width / CellSize; RowCount = height / CellSize; } catch (Exception) { throw; } //настройки таблицы for (int i = 1; i < crossParam.Length - 1; i++) { Word word = new Word(i); try { string[] paramStr = Regex.Split(crossParam[i], " "); word.XY = new Point(int.Parse(paramStr[0]), int.Parse(paramStr[1])); if (paramStr[3] == "H") { word.VH = false; } else if (paramStr[3] == "V") { word.VH = true; } word.Length = int.Parse(paramStr[2]); words.Add(word); } catch (Exception) { throw; } } tableLayoutPanel1.ColumnCount = ColumnCount; tableLayoutPanel1.RowCount = RowCount; this.tableLayoutPanel1.Size = new System.Drawing.Size(CellSize * ColumnCount + ColumnCount, CellSize * RowCount + RowCount); //отобразить for (int i = 0; i < ColumnCount; i++) { tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, CellSize)); } for (int i = 0; i < RowCount; i++) { tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, CellSize)); } TableClear(); for (int i = 0; i < words.Count; i++) { Dictionary<int, Point> wordP = words[i].WordPoint; foreach (var charP in wordP) { MyGroupBox btn = new MyGroupBox(); btn.Name = charP.Value.X.ToString() + " " + charP.Value.Y.ToString(); if (charP.Key == 0) { btn.Index = (i + 1).ToString(); } if (tableLayoutPanel1.Controls.Find(btn.Name, false).Length == 0) { tableLayoutPanel1.Controls.Add(btn); tableLayoutPanel1.SetCellPosition(btn, new TableLayoutPanelCellPosition(charP.Value.X, charP.Value.Y)); } else if (charP.Key == 0) { ((MyGroupBox)tableLayoutPanel1.GetControlFromPosition(charP.Value.X, charP.Value.Y)).Index = (i + 1).ToString(); } } } } }