private void Open_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { try { GraphFile file = new GraphFile(openFileDialog.FileName); if (sender == OpenA) { A = file.Read(); DrawA.Graph = A; InputA.Image = DrawA.Draw(); } else { B = file.Read(); DrawB.Graph = B; InputB.Image = DrawB.Draw(); } } catch (Exception) { MessageBox.Show("Error"); } } }
private void Input_MouseDoubleClick(object sender, MouseEventArgs e) { if (NodeBtn.Checked && AddBtn.Checked) { DrawGr work = sender == InputA ? DrawA : DrawB; Graph graph = work.Graph; List <string> T = sender == InputA ? wasA : wasB; SelectedNode = work.GetNode(e.X, e.Y); if (SelectedNode != null) { NodeText text = new NodeText { S = SelectedNode.Value }; try { if (text.ShowDialog() == DialogResult.OK) { if (!T.Contains(text.S) || text.S == SelectedNode.Value) { T.Remove(SelectedNode.Value); T.Add(text.S); SelectedNode.Value = text.S; ((PictureBox)sender).Image = work.Draw(); } else { MessageBox.Show("Имя занято"); } } } catch (Exception) { MessageBox.Show("Error"); } } } }
private void Input_MouseClick(object sender, MouseEventArgs e) { DrawGr work = sender == InputA ? DrawA : DrawB; Graph graph = work.Graph; if (NodeBtn.Checked) { List <string> T = sender == InputA ? wasA : wasB; if (AddBtn.Checked && work.Empty(e.X, e.Y)) { NodeText text = new NodeText(); try { if (text.ShowDialog() == DialogResult.OK) { if (!T.Contains(text.S)) { T.Add(text.S); graph.AddNode(text.S, e.X, e.Y); ((PictureBox)sender).Image = work.Draw(); } else { MessageBox.Show("Имя занято"); } } } catch (Exception) { MessageBox.Show("Error"); } } if (RemoveBtn.Checked) { SelectedNode = work.GetNode(e.X, e.Y); T.Remove(SelectedNode.Value); graph.RemoveNode(SelectedNode); ((PictureBox)sender).Image = work.Draw(); SelectedNode = null; } } else { if (SelectedNode == null || SelectedNode.Graph != graph) { SelectedNode = work.GetNode(e.X, e.Y); } else { Node second = work.GetNode(e.X, e.Y); if (second != null && second != SelectedNode) { if (AddBtn.Checked) { SelectedNode.AddEdgeTo(second); } else { SelectedNode.RemoveEdgeTo(second); } ((PictureBox)sender).Image = work.Draw(); } SelectedNode = null; } } }