private void NewToolbarItem_Click(object sender, EventArgs e) { if (graphBox != null) graphBox.Dispose(); graphBox = new GraphBox(); graphBox.Size = new Size(this.Size.Width - 40, this.Size.Height - 80); this.Controls.Add(graphBox); }
private void OpenToolbarItem_Click(object sender, EventArgs e) { // GraphBox initialization if (graphBox != null) graphBox.Dispose(); graphBox = new GraphBox(); graphBox.Size = new Size(this.Size.Width - 40, this.Size.Height - 80); this.Controls.Add(graphBox); // Opening file OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = "Graph files (*.g)|*.g"; openDialog.RestoreDirectory = true; try { if (openDialog.ShowDialog() == DialogResult.OK) { using (StreamReader sr = new StreamReader(openDialog.OpenFile(), System.Text.Encoding.Unicode)) { if (sr != null) { // Parsing Vertexes int vertCount = int.Parse(sr.ReadLine()); for (int i = 0; i < vertCount; i++) { graphBox.G += ToVetex(sr.ReadLine()); } // Parsing Edges int edgeCount = int.Parse(sr.ReadLine()); for (int i = 0; i < edgeCount; i++) { graphBox.G += ToEdge(sr.ReadLine()); } } } graphBuffer = graphBox.G.ToString(); } } catch (FormatException) { MessageBox.Show("File corrupted!" + Environment.NewLine + "Empty file will be opened.", "Error", MessageBoxButtons.OK); } }