Example #1
0
 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");
             }
         }
     }
 }
Example #2
0
        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;
                }
            }
        }