private void btnCreateListNode_Click(object sender, EventArgs e) { if (listNode != null) { for (int i = 0; i < SoNode; i++) { this.Controls.Remove(listNode[i].img); this.Controls.Remove(listNode[i].index); } } if (listTextbox != null) { listTextbox = null; } btnRandom.Enabled = true; btnManual.Enabled = true; SoNode = Int32.Parse(this.numNodeNumber.Value.ToString()); listNode = new Node[SoNode]; for (int i = 0; i < SoNode; i++) { Node a = NodeServices.CreateNode(0, new Point(i * 100 + 50, NodeServices.Ynode)); a.img.Text = ""; a.index.Text = "[" + i + "]"; this.Controls.Add(a.img); this.Controls.Add(a.index); listNode[i] = a; } Application.DoEvents(); btnSort.Enabled = false; btnPause.Enabled = false; btnContinue.Enabled = false; btnStop.Enabled = false; }
private void btnRandom_Click(object sender, EventArgs e) { listTextbox = null; for (int i = 0; i < SoNode; i++) { this.Controls.Remove(listNode[i].img); this.Controls.Remove(listNode[i].index); Node a = NodeServices.CreateNode(rad.Next(0, 100), new Point(i * 100 + 50, NodeServices.Ynode)); a.index.Text = "[" + i + "]"; this.Controls.Add(a.img); this.Controls.Add(a.index); listNode[i] = a; } Application.DoEvents(); btnSort.Enabled = true; }
private void btnReadFile_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Open file"; openFileDialog.ShowDialog(); string path = openFileDialog.FileName; if (path.Equals("")) { return; } StreamReader sr = null; try { sr = new StreamReader(path); string line; while ((line = sr.ReadLine()) != null) { string[] listString = line.Split(' '); int[] a = new int[listString.Length]; for (int i = 0; i < listString.Length; i++) { a[i] = Int32.Parse(listString[i]); } if (listNode != null) { for (int i = 0; i < SoNode; i++) { this.Controls.Remove(listNode[i].img); this.Controls.Remove(listNode[i].index); } } listTextbox = null; SoNode = listString.Length; if (SoNode > 10) { SoNode = 10; } listNode = new Node[SoNode]; for (int i = 0; i < SoNode; i++) { Node node = NodeServices.CreateNode(a[i], new Point(i * 100 + 50, NodeServices.Ynode)); listNode[i] = node; this.Controls.Add(node.img); this.Controls.Add(node.index); } NodeServices.DoEvent(); break; } } catch (Exception) { string st = "Khong the doc du lieu tu file da cho"; string caption = "Error"; MessageBox.Show(st, caption, MessageBoxButtons.OK); } finally { sr.Close(); } btnManual.Enabled = false; btnRandom.Enabled = false; btnSort.Enabled = true; }